diff --git a/Source/Core/DolphinQt/Config/Graphics/GraphicsWindow.cpp b/Source/Core/DolphinQt/Config/Graphics/GraphicsWindow.cpp index 2edac668d1..456b132847 100644 --- a/Source/Core/DolphinQt/Config/Graphics/GraphicsWindow.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/GraphicsWindow.cpp @@ -38,9 +38,6 @@ void GraphicsWindow::Initialize() m_lazy_initialized = true; - g_Config.Refresh(); - g_video_backend->InitBackendInfo(); - CreateMainLayout(); setWindowTitle(tr("Graphics")); @@ -109,18 +106,7 @@ void GraphicsWindow::CreateMainLayout() void GraphicsWindow::OnBackendChanged(const QString& backend_name) { SConfig::GetInstance().m_strVideoBackend = backend_name.toStdString(); - - for (const auto& backend : g_available_video_backends) - { - if (backend->GetName() == backend_name.toStdString()) - { - g_Config.Refresh(); - - g_video_backend = backend.get(); - g_video_backend->InitBackendInfo(); - break; - } - } + VideoBackendBase::PopulateBackendInfo(); setWindowTitle( tr("%1 Graphics Configuration").arg(tr(g_video_backend->GetDisplayName().c_str()))); diff --git a/Source/Core/VideoCommon/VideoBackendBase.cpp b/Source/Core/VideoCommon/VideoBackendBase.cpp index 327064a4f2..0e413b2d3c 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.cpp +++ b/Source/Core/VideoCommon/VideoBackendBase.cpp @@ -14,6 +14,8 @@ #include "Common/CommonTypes.h" #include "Common/Event.h" #include "Common/Logging/Log.h" +#include "Core/ConfigManager.h" +#include "Core/Core.h" #include "Core/Host.h" // TODO: ugly @@ -223,6 +225,20 @@ void VideoBackendBase::ActivateBackend(const std::string& name) g_video_backend = iter->get(); } +void VideoBackendBase::PopulateBackendInfo() +{ + // If the core is running, the backend info will have been populated already. + // If we did it here, the UI thread can race with the with the GPU thread. + if (Core::IsRunning()) + return; + + // We refresh the config after initializing the backend info, as system-specific settings + // such as anti-aliasing, or the selected adapter may be invalid, and should be checked. + ActivateBackend(SConfig::GetInstance().m_strVideoBackend); + g_video_backend->InitBackendInfo(); + g_Config.Refresh(); +} + // Run from the CPU thread void VideoBackendBase::DoState(PointerWrap& p) { diff --git a/Source/Core/VideoCommon/VideoBackendBase.h b/Source/Core/VideoCommon/VideoBackendBase.h index 35a35583c3..5f43b904d4 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.h +++ b/Source/Core/VideoCommon/VideoBackendBase.h @@ -54,6 +54,10 @@ public: static void ClearList(); static void ActivateBackend(const std::string& name); + // Fills the backend_info fields with the capabilities of the selected backend/device. + // Called by the UI thread when the graphics config is opened. + static void PopulateBackendInfo(); + // the implementation needs not do synchronization logic, because calls to it are surrounded by // PauseAndLock now void DoState(PointerWrap& p);