From 3fc845a265ed39a0de10869ea8fd66af02a75356 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 22 Aug 2018 18:27:20 -0700 Subject: [PATCH] UI: Delay game config/discord until game info load. This avoids a race condition where the info is not always available, causing game-specific config and Discord presence to set incorrectly. --- UI/EmuScreen.cpp | 11 +++++++---- UI/GameInfoCache.cpp | 7 ++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index e34a8e10c7..feeb5b8cb6 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -189,9 +189,14 @@ void EmuScreen::bootGame(const std::string &filename) { I18NCategory *sc = GetI18NCategory("Screen"); - //pre-emptive loading of game specific config if possible, to get all the settings + invalid_ = true; + + // We don't want to boot with the wrong game specific config, so wait until info is ready. std::shared_ptr info = g_gameInfoCache->GetInfo(nullptr, filename, 0); - if (info && !info->id.empty()) { + if (!info || info->pending) + return; + + if (!info->id.empty()) { g_Config.loadGameConfig(info->id); // Reset views in case controls are in a different place. RecreateViews(); @@ -201,8 +206,6 @@ void EmuScreen::bootGame(const std::string &filename) { g_Discord.SetPresenceGame(sc->T("Untitled PSP game")); } - invalid_ = true; - CoreParameter coreParam{}; coreParam.cpuCore = (CPUCore)g_Config.iCpuCore; coreParam.gpuCore = GPUCORE_GLES; diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index f2a5e9f431..f727aa1363 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -353,8 +353,10 @@ public: } void run() override { - if (!info_->LoadFromPath(gamePath_)) + if (!info_->LoadFromPath(gamePath_)) { + info_->pending = false; return; + } // In case of a remote file, check if it actually exists before locking. if (!info_->GetFileLoader()->Exists()) { info_->pending = false; @@ -381,6 +383,7 @@ public: goto handleELF; } ERROR_LOG(LOADER, "invalid pbp %s\n", pbpLoader->Path().c_str()); + info_->pending = false; info_->working = false; return; } @@ -549,11 +552,13 @@ handleELF: // few files. auto fl = info_->GetFileLoader(); if (!fl) { + info_->pending = false; info_->working = false; return; // Happens with UWP currently, TODO... } BlockDevice *bd = constructBlockDevice(info_->GetFileLoader().get()); if (!bd) { + info_->pending = false; info_->working = false; return; // nothing to do here.. }