Skip to content

Commit c0d16da

Browse files
committed
fix: MMNotificationClient callback might be called during game shutdown, prevent a crash
1 parent e5e490c commit c0d16da

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

bmedll/MMNotificationClient.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ HRESULT STDMETHODCALLTYPE MMNotificationClient::QueryInterface(REFIID riid, VOID
4444

4545
HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDeviceId)
4646
{
47+
if (!IsSDKReady())
48+
return;
4749
if (role == eMultimedia)
4850
{
4951
spdlog::info("[MMNotificationClient::OnDefaultDeviceChanged] Default multimedia audio device changed, requesting game's XAudio to restart.");
5052
int refresh_rate = *reinterpret_cast<int*>(Util::GetModuleBaseAddress("engine.dll") + 0x7CAEA4);
51-
SDK().AddDelayedFunc([] { SDK().GetConCommandManager().ExecuteCommand("sound_reboot_xaudio"); }, refresh_rate);
53+
SDK().AddDelayedFunc([] { if (IsSDKReady()) SDK().GetConCommandManager().ExecuteCommand("sound_reboot_xaudio"); }, refresh_rate);
5254
}
5355
return S_OK;
5456
}

0 commit comments

Comments
 (0)