1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Made a few of the AudioIODeviceType subclasses weak referenceable to avoid dangling references

This commit is contained in:
ed 2019-01-16 10:35:40 +00:00
parent 87281fc784
commit c9a7b41864
4 changed files with 35 additions and 22 deletions

View file

@ -1518,7 +1518,7 @@ private:
class ChangeNotificationClient : public ComBaseClassHelper<IMMNotificationClient>
{
public:
ChangeNotificationClient (WASAPIAudioIODeviceType& d)
ChangeNotificationClient (WASAPIAudioIODeviceType* d)
: ComBaseClassHelper<IMMNotificationClient> (0), device (d) {}
HRESULT STDMETHODCALLTYPE OnDeviceAdded (LPCWSTR) { return notify(); }
@ -1528,9 +1528,15 @@ private:
HRESULT STDMETHODCALLTYPE OnPropertyValueChanged (LPCWSTR, const PROPERTYKEY) { return notify(); }
private:
WASAPIAudioIODeviceType& device;
WeakReference<WASAPIAudioIODeviceType> device;
HRESULT notify() { device.triggerAsyncDeviceChangeCallback(); return S_OK; }
HRESULT notify()
{
if (device != nullptr)
device->triggerAsyncDeviceChangeCallback();
return S_OK;
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChangeNotificationClient)
};
@ -1571,7 +1577,7 @@ private:
if (! check (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator))))
return;
notifyClient = new ChangeNotificationClient (*this);
notifyClient = new ChangeNotificationClient (this);
enumerator->RegisterEndpointNotificationCallback (notifyClient);
}
@ -1660,6 +1666,7 @@ private:
}
//==============================================================================
JUCE_DECLARE_WEAK_REFERENCEABLE (WASAPIAudioIODeviceType)
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WASAPIAudioIODeviceType)
};