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.
master
minerjr 2025-10-28 23:30:18 -03:00
parent 6ad9a57c39
commit cc3bae406c
2 changed files with 26 additions and 1 deletions

View File

@ -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)
// <FS:minerjr> [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 = { };
// <FS:minerjr> [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);
// </FS:minerjr> [FIRE-36022]
mSystem->getAdvancedSettings(&settings_dump);
LL_INFOS("AppInit") << "LLAudioEngine_FMODSTUDIO::init(): resampler=" << settings_dump.resamplerMethod << " bytes" << LL_ENDL;

View File

@ -1016,6 +1016,11 @@ bool LLAppViewerWin32::cleanup()
gDXHardware.cleanup();
// <FS:minerjr> [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();
// </FS:minerjr> [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;
}
}
// <FS:minerjr> [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;
}
// </FS:minerjr> [FIRE-36022]
return LLAppViewer::initWindow();
}