Skip to content

Commit

Permalink
Merge pull request musescore#18392 from Eism/wasapi_device_null_check
Browse files Browse the repository at this point in the history
fixed musescore#18161: Crash unplugging USB on Windows
  • Loading branch information
RomanPudashkin committed Jul 5, 2023
2 parents 548dd7b + 95c9cd6 commit d2cec8a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -118,11 +118,13 @@ HRESULT AudioDevicesListener::OnDefaultDeviceChanged(EDataFlow flow, ERole role,
return S_OK;
}

if (m_previousIdString == new_default_device_id) {
winrt::hstring newDefaultDeviceIdString = new_default_device_id ? new_default_device_id : winrt::hstring();

if (m_previousDefaultDeviceId == newDefaultDeviceIdString) {
return S_OK;
}

m_previousIdString = new_default_device_id;
m_previousDefaultDeviceId = newDefaultDeviceIdString;

m_defaultDeviceChanged.notify();
m_devicesChanged.notify();
Expand Down
Expand Up @@ -47,7 +47,7 @@ class AudioDevicesListener : public IMMNotificationClient
STDMETHOD(OnPropertyValueChanged)(LPCWSTR device_id, const PROPERTYKEY key);

winrt::com_ptr<IMMDeviceEnumerator> m_deviceEnumerator;
winrt::hstring m_previousIdString;
winrt::hstring m_previousDefaultDeviceId;

async::Notification m_devicesChanged;
async::Notification m_defaultDeviceChanged;
Expand Down

0 comments on commit d2cec8a

Please sign in to comment.