[qt] fix crash when having an invalid graphics backend (#3693)

closely related to #3692, however the crash may also occur when sharing configs between macOS and a system that had OpenGL

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3693
Reviewed-by: DraVee <chimera@dravee.dev>
Reviewed-by: crueter <crueter@eden-emu.dev>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie 2026-03-08 20:48:47 +01:00 committed by crueter
parent 80bafc8fe8
commit 0a169dec4d
No known key found for this signature in database
GPG key ID: 425ACD2D4830EBC6

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project // SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2016 Citra Emulator Project // SPDX-FileCopyrightText: 2016 Citra Emulator Project
@ -416,11 +416,9 @@ const QString ConfigureGraphics::TranslateVSyncMode(VkPresentModeKHR mode,
} }
int ConfigureGraphics::FindIndex(u32 enumeration, int value) const { int ConfigureGraphics::FindIndex(u32 enumeration, int value) const {
for (u32 i = 0; i < combobox_translations.at(enumeration).size(); i++) { for (u32 i = 0; enumeration < combobox_translations.size() && i < combobox_translations.at(enumeration).size(); i++)
if (combobox_translations.at(enumeration)[i].first == static_cast<u32>(value)) { if (combobox_translations.at(enumeration)[i].first == u32(value))
return i; return i;
}
}
return -1; return -1;
} }
@ -433,13 +431,11 @@ void ConfigureGraphics::ApplyConfiguration() {
UpdateVsyncSetting(); UpdateVsyncSetting();
Settings::values.vulkan_device.SetGlobal(true); Settings::values.vulkan_device.SetGlobal(true);
if (Settings::IsConfiguringGlobal() || auto const index = Settings::EnumMetadata<Settings::RendererBackend>::Index();
(!Settings::IsConfiguringGlobal() && api_restore_global_button->isEnabled())) { if (Settings::IsConfiguringGlobal() || (!Settings::IsConfiguringGlobal() && api_restore_global_button->isEnabled())) {
auto backend = static_cast<Settings::RendererBackend>( auto backend = index >= combobox_translations.size() || size_t(api_combobox->currentIndex()) >= combobox_translations.at(index).size()
combobox_translations ? Settings::values.renderer_backend.GetValue()
.at(Settings::EnumMetadata< : Settings::RendererBackend(combobox_translations.at(index)[api_combobox->currentIndex()].first);
Settings::RendererBackend>::Index())[api_combobox->currentIndex()]
.first);
switch (backend) { switch (backend) {
case Settings::RendererBackend::Vulkan: case Settings::RendererBackend::Vulkan:
Settings::values.vulkan_device.SetGlobal(Settings::IsConfiguringGlobal()); Settings::values.vulkan_device.SetGlobal(Settings::IsConfiguringGlobal());
@ -507,13 +503,12 @@ void ConfigureGraphics::RetrieveVulkanDevices() {
Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const { Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const {
const auto selected_backend = [&]() { const auto selected_backend = [&]() {
if (!Settings::IsConfiguringGlobal() && !api_restore_global_button->isEnabled()) { auto const index = Settings::EnumMetadata<Settings::RendererBackend>::Index();
if (!Settings::IsConfiguringGlobal() && !api_restore_global_button->isEnabled())
return Settings::values.renderer_backend.GetValue(true); return Settings::values.renderer_backend.GetValue(true);
} return index >= combobox_translations.size() || size_t(api_combobox->currentIndex()) >= combobox_translations.at(index).size()
return Settings::RendererBackend( ? Settings::values.renderer_backend.GetValue()
combobox_translations.at(Settings::EnumMetadata<Settings::RendererBackend>::Index()) : Settings::RendererBackend(combobox_translations.at(index).at(api_combobox->currentIndex()).first);
.at(api_combobox->currentIndex())
.first);
}(); }();
if (selected_backend == Settings::RendererBackend::Vulkan && UISettings::values.has_broken_vulkan) if (selected_backend == Settings::RendererBackend::Vulkan && UISettings::values.has_broken_vulkan)