From c44500ba0f38e948394c0ea67cb695624aee5928 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 24 Jun 2024 21:17:31 +1000 Subject: [PATCH] Achievements: Fix async HC mode disable running on wrong thread --- pcsx2/Achievements.cpp | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/pcsx2/Achievements.cpp b/pcsx2/Achievements.cpp index 9b92704de8..4ecf807881 100644 --- a/pcsx2/Achievements.cpp +++ b/pcsx2/Achievements.cpp @@ -1855,30 +1855,32 @@ void Achievements::ConfirmHardcoreModeDisableAsync(const char* trigger, std::fun } #endif - if (!FullscreenUI::Initialize()) - { - Host::AddOSDMessage(fmt::format(TRANSLATE_FS("Cannot {} while hardcode mode is active.", trigger)), - Host::OSD_WARNING_DURATION); - callback(false); - return; - } + MTGS::RunOnGSThread([trigger = TinyString(trigger), callback = std::move(callback)]() { + if (!FullscreenUI::Initialize()) + { + Host::AddOSDMessage(fmt::format(TRANSLATE_FS("Cannot {} while hardcode mode is active.", trigger)), + Host::OSD_WARNING_DURATION); + callback(false); + return; + } - auto real_callback = [callback = std::move(callback)](bool res) mutable { - // don't run the callback in the middle of rendering the UI - Host::RunOnCPUThread([callback = std::move(callback), res]() { - if (res) - DisableHardcoreMode(); - callback(res); - }); - }; + auto real_callback = [callback = std::move(callback)](bool res) mutable { + // don't run the callback in the middle of rendering the UI + Host::RunOnCPUThread([callback = std::move(callback), res]() { + if (res) + DisableHardcoreMode(); + callback(res); + }); + }; - ImGuiFullscreen::OpenConfirmMessageDialog( - TRANSLATE_STR("Achievements", "Confirm Hardcore Mode"), - fmt::format(TRANSLATE_FS("Achievements", "{0} cannot be performed while hardcore mode is active. Do you " - "want to disable hardcore mode? {0} will be cancelled if you select No."), - trigger), - std::move(real_callback), fmt::format(ICON_FA_CHECK " {}", TRANSLATE_SV("Achievements", "Yes")), - fmt::format(ICON_FA_TIMES " {}", TRANSLATE_SV("Achievements", "No"))); + ImGuiFullscreen::OpenConfirmMessageDialog( + TRANSLATE_STR("Achievements", "Confirm Hardcore Mode"), + fmt::format(TRANSLATE_FS("Achievements", "{0} cannot be performed while hardcore mode is active. Do you " + "want to disable hardcore mode? {0} will be cancelled if you select No."), + trigger), + std::move(real_callback), fmt::format(ICON_FA_CHECK " {}", TRANSLATE_SV("Achievements", "Yes")), + fmt::format(ICON_FA_TIMES " {}", TRANSLATE_SV("Achievements", "No"))); + }); } void Achievements::ClearUIState()