From 249d8a76e163c7b899f5f636cddc8bc913624224 Mon Sep 17 00:00:00 2001 From: EmptyChaos Date: Sat, 24 Sep 2016 03:17:39 +0000 Subject: [PATCH] GeckoCode: Don't spam retry after the install fails If the installation fails because codehandler.bin is missing or unusable then Dolphin will try again every single frame even though it's highly unlikely a disk file will have changed. Better to just fail once then only try again when the active code set is changed. Suppresses generating 60 log messages per second. --- Source/Core/Core/GeckoCode.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index 7e033a8d9e..63c22a7599 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -39,7 +39,14 @@ bool GeckoCode::Compare(const GeckoCode& compare) const }); } -static bool s_code_handler_installed = false; +enum class Installation +{ + Uninstalled, + Installed, + Failed +}; + +static Installation s_code_handler_installed = Installation::Uninstalled; // the currently active codes static std::vector s_active_codes; static std::mutex s_active_codes_lock; @@ -54,24 +61,24 @@ void SetActiveCodes(const std::vector& gcodes) [](const GeckoCode& code) { return code.enabled; }); s_active_codes.shrink_to_fit(); - s_code_handler_installed = false; + s_code_handler_installed = Installation::Uninstalled; } // Requires s_active_codes_lock // NOTE: Refer to "codehandleronly.s" from Gecko OS. -static bool InstallCodeHandlerLocked() +static Installation InstallCodeHandlerLocked() { std::string data; if (!File::ReadFileToString(File::GetSysDirectory() + GECKO_CODE_HANDLER, data)) { ERROR_LOG(ACTIONREPLAY, "Could not enable cheats because " GECKO_CODE_HANDLER " was missing."); - return false; + return Installation::Failed; } if (data.size() > INSTALLER_END_ADDRESS - INSTALLER_BASE_ADDRESS - CODE_SIZE) { ERROR_LOG(ACTIONREPLAY, GECKO_CODE_HANDLER " is too big. The file may be corrupt."); - return false; + return Installation::Failed; } u8 mmio_addr = 0xCC; @@ -148,7 +155,7 @@ static bool InstallCodeHandlerLocked() { PowerPC::ppcState.iCache.Invalidate(INSTALLER_BASE_ADDRESS + j); } - return true; + return Installation::Installed; } void RunCodeHandler() @@ -157,15 +164,17 @@ void RunCodeHandler() return; std::lock_guard codes_lock(s_active_codes_lock); - if (s_active_codes.empty()) + // Don't spam retry if the install failed. The corrupt / missing disk file is not likely to be + // fixed within 1 frame of the last error. + if (s_active_codes.empty() || s_code_handler_installed == Installation::Failed) return; - if (!s_code_handler_installed) + if (s_code_handler_installed != Installation::Installed) { s_code_handler_installed = InstallCodeHandlerLocked(); // A warning was already issued for the install failing - if (!s_code_handler_installed) + if (s_code_handler_installed != Installation::Installed) return; }