diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 7fff1ba28f..1b391ed83f 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -841,6 +841,10 @@ void OTRGlobals::Initialize() { // jitter and slow-frame spikes without perceptible audio latency. .DesiredBuffered = 4096 }); + // The menu is set up before audio is initialized, so its list of available audio backends has to be + // populated here rather than in Menu::InitElement (where the window backends are handled). + SohGui::GetSohMenu()->UpdateAudioBackendObjects(); + SPDLOG_INFO("Starting Ship of Harkinian version {} (Branch: {} | Commit: {})", (char*)gBuildVersion, (char*)gGitBranch, (char*)gGitCommitHash); diff --git a/soh/soh/SohGui/Menu.cpp b/soh/soh/SohGui/Menu.cpp index f637ecb10d..c41bfe74a4 100644 --- a/soh/soh/SohGui/Menu.cpp +++ b/soh/soh/SohGui/Menu.cpp @@ -98,6 +98,13 @@ void Menu::RemoveSidebarSearch() { CVarSetString(menuEntries["Settings"].sidebarCvar, menuEntries["Settings"].sidebarOrder.at(curIndex).c_str()); } +void Menu::UpdateAudioBackendObjects() { + availableAudioBackends = Ship::Context::GetRawInstance()->GetAudio()->GetAvailableAudioBackends(); + for (auto& backend : *availableAudioBackends) { + availableAudioBackendsMap[backend] = audioBackendsMap.at(backend); + } +} + void Menu::UpdateWindowBackendObjects() { Fast::WindowBackend runningWindowBackend = (Fast::WindowBackend)Ship::Context::GetRawInstance()->GetWindow()->GetWindowBackend(); @@ -341,10 +348,9 @@ void Menu::MenuDrawItem(WidgetInfo& widget, uint32_t width, UIWidgets::Colors me UIWidgets::ComboboxOptions options = {}; options.color = menuThemeIndex; options.tooltip = "Sets the audio API used by the game. Requires a relaunch to take effect."; - options.disabled = - Ship::Context::GetRawInstance()->GetAudio()->GetAvailableAudioBackends()->size() <= 1; + options.disabled = availableAudioBackends->size() <= 1; options.disabledTooltip = "Only one audio API is available on this platform."; - if (UIWidgets::Combobox("Audio API", ¤tAudioBackend, audioBackendsMap, options)) { + if (UIWidgets::Combobox("Audio API", ¤tAudioBackend, availableAudioBackendsMap, options)) { Ship::Context::GetRawInstance()->GetAudio()->SetCurrentAudioBackend(currentAudioBackend); } } break; diff --git a/soh/soh/SohGui/Menu.h b/soh/soh/SohGui/Menu.h index e8c3c0c274..7fcbab7a93 100644 --- a/soh/soh/SohGui/Menu.h +++ b/soh/soh/SohGui/Menu.h @@ -20,6 +20,7 @@ class Menu : public GuiWindow { void Draw() override; void InsertSidebarSearch(); void RemoveSidebarSearch(); + void UpdateAudioBackendObjects(); void UpdateWindowBackendObjects(); bool IsMenuPopped(); UIWidgets::Colors GetMenuThemeColor(); @@ -42,6 +43,8 @@ class Menu : public GuiWindow { std::shared_ptr> availableWindowBackends; std::map availableWindowBackendsMap; Fast::WindowBackend configWindowBackend; + std::shared_ptr> availableAudioBackends; + std::map availableAudioBackendsMap; std::unordered_map disabledMap; std::vector disabledVector;