diff options
| author | JosJuice <josjuice@gmail.com> | 2025-04-26 09:06:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-26 09:06:06 +0200 |
| commit | 3e5286c1a403c753ef81e6645022722b8ea5929a (patch) | |
| tree | 83f56a15010c8133860c5792b234eb9094665ca4 /Source/Core/VideoCommon/VideoConfig.cpp | |
| parent | 805307f432dba079caf7339122a07de5b90c4b47 (diff) | |
| parent | 3a883f28d675f971509c165cfedeba861ecdd48a (diff) | |
Merge pull request #13593 from Dentomologist/mainwindow_fix_use_after_free_during_dolphin_shutdown
MainWindow: Fix use-after-free during Dolphin shutdown
Diffstat (limited to 'Source/Core/VideoCommon/VideoConfig.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VideoConfig.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index b540358fb1..fb5fb41b05 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -4,6 +4,7 @@ #include "VideoCommon/VideoConfig.h" #include <algorithm> +#include <optional> #include "Common/CPUDetect.h" #include "Common/CommonTypes.h" @@ -33,7 +34,8 @@ VideoConfig g_Config; VideoConfig g_ActiveConfig; BackendInfo g_backend_info; -static bool s_has_registered_callback = false; +static std::optional<CPUThreadConfigCallback::ConfigChangedCallbackID> + s_config_changed_callback_id = std::nullopt; static bool IsVSyncActive(bool enabled) { @@ -50,14 +52,14 @@ void UpdateActiveConfig() void VideoConfig::Refresh() { - if (!s_has_registered_callback) + if (!s_config_changed_callback_id.has_value()) { // There was a race condition between the video thread and the host thread here, if // corrections need to be made by VerifyValidity(). Briefly, the config will contain // invalid values. Instead, pause the video thread first, update the config and correct // it, then resume emulation, after which the video thread will detect the config has // changed and act accordingly. - CPUThreadConfigCallback::AddConfigChangedCallback([]() { + const auto config_changed_callback = []() { auto& system = Core::System::GetInstance(); const bool lock_gpu_thread = Core::IsRunning(system); @@ -69,8 +71,10 @@ void VideoConfig::Refresh() if (lock_gpu_thread) system.GetFifo().PauseAndLock(false, true); - }); - s_has_registered_callback = true; + }; + + s_config_changed_callback_id = + CPUThreadConfigCallback::AddConfigChangedCallback(config_changed_callback); } bVSync = Config::Get(Config::GFX_VSYNC); @@ -212,6 +216,15 @@ void VideoConfig::VerifyValidity() } } +void VideoConfig::Shutdown() +{ + if (!s_config_changed_callback_id.has_value()) + return; + + CPUThreadConfigCallback::RemoveConfigChangedCallback(*s_config_changed_callback_id); + s_config_changed_callback_id.reset(); +} + bool VideoConfig::UsingUberShaders() const { return iShaderCompilationMode == ShaderCompilationMode::SynchronousUberShaders || |
