diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 4380c6b37a..3901033699 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -303,6 +303,11 @@ bool GameInfo::IsPending() { return pending; } +bool GameInfo::IsWorking() { + lock_guard guard(lock); + return working; +} + void GameInfo::SetTitle(const std::string &newTitle) { lock_guard guard(lock); title = newTitle; @@ -360,6 +365,7 @@ public: std::string filename = gamePath_; { lock_guard lock(info_->lock); + info_->working = true; info_->fileType = Identify_File(info_->GetFileLoader()); } @@ -591,6 +597,7 @@ handleELF: lock_guard lock(info_->lock); info_->pending = false; + info_->working = false; // ILOG("Completed writing info for %s", info_->GetTitle().c_str()); } @@ -755,8 +762,14 @@ again: if (!info) { info = new GameInfo(); } + { lock_guard lock(info->lock); + if (info->IsWorking()) { + // Uh oh, it's currently in process. It could mark pending = false with the wrong wantFlags. + // Let's wait it out, then queue. + WaitUntilDone(info); + } info->wantFlags |= wantFlags; info->pending = true; } diff --git a/UI/GameInfoCache.h b/UI/GameInfoCache.h index 1cea1ce090..70eba8749a 100644 --- a/UI/GameInfoCache.h +++ b/UI/GameInfoCache.h @@ -98,7 +98,7 @@ public: : disc_total(0), disc_number(0), region(-1), fileType(FILETYPE_UNKNOWN), paramSFOLoaded(false), hasConfig(false), iconTexture(nullptr), pic0Texture(nullptr), pic1Texture(nullptr), wantFlags(0), lastAccessedTime(0.0), timeIconWasLoaded(0.0), timePic0WasLoaded(0.0), timePic1WasLoaded(0.0), - gameSize(0), saveDataSize(0), installDataSize(0), pending(true), fileLoader(nullptr) {} + gameSize(0), saveDataSize(0), installDataSize(0), pending(true), working(false), fileLoader(nullptr) {} ~GameInfo(); bool Delete(); // Better be sure what you're doing when calling this. @@ -120,6 +120,7 @@ public: void SetTitle(const std::string &newTitle); bool IsPending(); + bool IsWorking(); // Hold this when reading or writing from the GameInfo. // Don't need to hold it when just passing around the pointer, @@ -166,6 +167,7 @@ public: u64 saveDataSize; u64 installDataSize; bool pending; + bool working; protected: // Note: this can change while loading, use GetTitle().