From cc3bae406c2bf788f7b0c0237699b708714dde06 Mon Sep 17 00:00:00 2001 From: minerjr Date: Tue, 28 Oct 2025 23:30:18 -0300 Subject: [PATCH] FIRE-36022 - Removing my USB headset crashes entire viewer - FMOD fixes Added three FMOD specific changes based upon reading the FMOD manual. See: https://www.fmod.com/docs/2.00/api/platforms-win.html As well, switched to using the FMOD log version of the library and found one error on the get advanced features. Also, the call back method should be a static method. Just being cautious. --- indra/llaudio/llaudioengine_fmodstudio.cpp | 9 ++++++++- indra/newview/llappviewerwin32.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/indra/llaudio/llaudioengine_fmodstudio.cpp b/indra/llaudio/llaudioengine_fmodstudio.cpp index 03964762b2..36b35efb47 100644 --- a/indra/llaudio/llaudioengine_fmodstudio.cpp +++ b/indra/llaudio/llaudioengine_fmodstudio.cpp @@ -116,8 +116,10 @@ static void set_device(FMOD::System* system, const LLUUID& device_uuid) } } -FMOD_RESULT F_CALL systemCallback(FMOD_SYSTEM *system, FMOD_SYSTEM_CALLBACK_TYPE type, void *commanddata1, void *commanddata2, void* userdata) // [FIRE-36022] - Removing my USB headset crashes entire viewer +// According to FMOD, not having this method static is very bad. +//FMOD_RESULT F_CALL systemCallback(FMOD_SYSTEM *system, FMOD_SYSTEM_CALLBACK_TYPE type, void *commanddata1, void *commanddata2, void* userdata) +static FMOD_RESULT F_CALL systemCallback(FMOD_SYSTEM *system, FMOD_SYSTEM_CALLBACK_TYPE type, void *commanddata1, void *commanddata2, void* userdata) { try // Try catch needed for uniquie lock as will throw an exception if a second lock is attempted or the mutex is invalid { @@ -357,6 +359,11 @@ bool LLAudioEngine_FMODSTUDIO::init(void* userdata, const std::string &app_title LL_INFOS("AppInit") << "LLAudioEngine_FMODSTUDIO::init() FMOD Studio initialized correctly" << LL_ENDL; FMOD_ADVANCEDSETTINGS settings_dump = { }; + // [FIRE-36022] - Removing my USB headset crashes entire viewer + // With the FMOD debug library used, turns out this object needs to have a size assigned to it otherwise it will fail. + // So the viewer never got any advanced settings for the info below. + settings_dump.cbSize = sizeof(FMOD_ADVANCEDSETTINGS); + // [FIRE-36022] mSystem->getAdvancedSettings(&settings_dump); LL_INFOS("AppInit") << "LLAudioEngine_FMODSTUDIO::init(): resampler=" << settings_dump.resamplerMethod << " bytes" << LL_ENDL; diff --git a/indra/newview/llappviewerwin32.cpp b/indra/newview/llappviewerwin32.cpp index ba3e900580..bf12160aa0 100644 --- a/indra/newview/llappviewerwin32.cpp +++ b/indra/newview/llappviewerwin32.cpp @@ -1016,6 +1016,11 @@ bool LLAppViewerWin32::cleanup() gDXHardware.cleanup(); + // [FIRE-36022] - Removing my USB headset crashes entire viewer + // Need to unilitialize connection to COM, otherwise it will be treated as a memroy leak. + CoUninitialize(); + // [FIRE-36022] + if (mIsConsoleAllocated) { FreeConsole(); @@ -1056,6 +1061,19 @@ bool LLAppViewerWin32::initWindow() LL_WARNS("AppInit") << "Unable to set WindowWidth and WindowHeight for FullScreen mode" << LL_ENDL; } } + // [FIRE-36022] - Removing my USB headset crashes entire viewer + // Acccording to the FMOD spec, you are suppose to initalize COM on the thead that will talk to FMOD. IE the main thread. + // There is a coorisponding CoUninitialize in the shutdown code. Otherwise, FMOD will force the initalize with a warning, but does not clean up COM + HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + if (SUCCEEDED(hr)) + { + LL_INFOS() << "WIN32: CoInitializeEx COM as COINIT_APARTMENTTHREADED Successful" << LL_ENDL; + } + else + { + LL_INFOS() << "WIN32: CoInitializeEx COM as COINIT_APARTMENTTHREADED Failed" << LL_ENDL; + } + // [FIRE-36022] return LLAppViewer::initWindow(); }