Browse Source

Windows MIDI: Fixed an issue where opening the same device twice would cause a crash when both devices were deleted

tags/2021-05-28
hogliux 7 years ago
parent
commit
508ba421e8
1 changed files with 20 additions and 18 deletions
  1. +20
    -18
      modules/juce_audio_devices/native/juce_win32_Midi.cpp

+ 20
- 18
modules/juce_audio_devices/native/juce_win32_Midi.cpp View File

@@ -321,9 +321,25 @@ private:
//==============================================================================
struct WindowsOutputWrapper : public OutputWrapper
{
struct MidiOutHandle
struct MidiOutHandle : public ReferenceCountedObject
{
int refCount;
using Ptr = ReferenceCountedObjectPtr<MidiOutHandle>;
MidiOutHandle (WindowsMidiService& parent, UINT id, HMIDIOUT h)
: owner (parent), deviceId (id), handle (h)
{
owner.activeOutputHandles.add (this);
}
~MidiOutHandle()
{
if (handle != nullptr)
midiOutClose (handle);
owner.activeOutputHandles.removeFirstMatchingValue (this);
}
WindowsMidiService& owner;
UINT deviceId;
HMIDIOUT handle;
@@ -356,7 +372,6 @@ private:
if (activeHandle->deviceId == deviceId)
{
activeHandle->refCount++;
han = activeHandle;
return;
}
@@ -369,11 +384,7 @@ private:
if (res == MMSYSERR_NOERROR)
{
han = new MidiOutHandle();
han->deviceId = deviceId;
han->refCount = 1;
han->handle = h;
parent.activeOutputHandles.add (han);
han = new MidiOutHandle (parent, deviceId, h);
return;
}
@@ -386,15 +397,6 @@ private:
throw std::runtime_error ("Failed to create Windows output device wrapper");
}
~WindowsOutputWrapper()
{
if (parent.activeOutputHandles.contains (han.get()) && --(han->refCount) == 0)
{
midiOutClose (han->handle);
parent.activeOutputHandles.removeFirstMatchingValue (han.get());
}
}
void sendMessageNow (const MidiMessage& message) override
{
if (message.getRawDataSize() > 3 || message.isSysEx())
@@ -489,7 +491,7 @@ private:
WindowsMidiService& parent;
String deviceName;
ScopedPointer<MidiOutHandle> han;
MidiOutHandle::Ptr han;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WindowsOutputWrapper)
};


Loading…
Cancel
Save