Merge pull request #12922 from JosJuice/android-approved-list-crash

RetroAchievements: Delay calling LoadApprovedList
This commit is contained in:
Admiral H. Curtiss 2024-07-09 15:27:37 +02:00 committed by GitHub
commit bb03fc04cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 10 deletions

View File

@ -72,7 +72,7 @@ void AchievementManager::Init()
}
}
void AchievementManager::LoadApprovedList()
picojson::value AchievementManager::LoadApprovedList()
{
picojson::value temp;
std::string error;
@ -82,7 +82,7 @@ void AchievementManager::LoadApprovedList()
WARN_LOG_FMT(ACHIEVEMENTS, "Failed to load approved game settings list {}",
APPROVED_LIST_FILENAME);
WARN_LOG_FMT(ACHIEVEMENTS, "Error: {}", error);
return;
return {};
}
auto context = Common::SHA1::CreateContext();
context->Update(temp.serialize());
@ -94,10 +94,9 @@ void AchievementManager::LoadApprovedList()
WARN_LOG_FMT(ACHIEVEMENTS, "Expected hash {}, found hash {}",
Common::SHA1::DigestToString(APPROVED_LIST_HASH),
Common::SHA1::DigestToString(digest));
return;
return {};
}
std::lock_guard lg{m_lock};
m_ini_root = std::move(temp);
return temp;
}
void AchievementManager::SetUpdateCallback(UpdateCallback callback)
@ -362,10 +361,18 @@ bool AchievementManager::IsHardcoreModeActive() const
void AchievementManager::FilterApprovedPatches(std::vector<PatchEngine::Patch>& patches,
const std::string& game_ini_id) const
{
if (patches.empty())
{
// There's nothing to verify, so let's save ourselves some work
return;
}
std::lock_guard lg{m_lock};
if (!IsHardcoreModeActive())
return;
if (!m_ini_root.contains(game_ini_id))
if (!m_ini_root->contains(game_ini_id))
patches.clear();
auto patch_itr = patches.begin();
while (patch_itr != patches.end())
@ -384,7 +391,7 @@ void AchievementManager::FilterApprovedPatches(std::vector<PatchEngine::Patch>&
}
auto digest = context->Finish();
bool verified = m_ini_root.get(game_ini_id).contains(Common::SHA1::DigestToString(digest));
bool verified = m_ini_root->get(game_ini_id).contains(Common::SHA1::DigestToString(digest));
if (!verified)
{
patch_itr = patches.erase(patch_itr);

View File

@ -29,6 +29,7 @@
#include "Common/Event.h"
#include "Common/HttpRequest.h"
#include "Common/JsonUtil.h"
#include "Common/Lazy.h"
#include "Common/WorkQueueThread.h"
#include "DiscIO/Volume.h"
#include "VideoCommon/Assets/CustomTextureData.h"
@ -146,7 +147,7 @@ public:
void Shutdown();
private:
AchievementManager() { LoadApprovedList(); };
AchievementManager() = default;
struct FilereaderState
{
@ -154,7 +155,7 @@ private:
std::unique_ptr<DiscIO::Volume> volume;
};
void LoadApprovedList();
static picojson::value LoadApprovedList();
static void* FilereaderOpenByFilepath(const char* path_utf8);
static void* FilereaderOpenByVolume(const char* path_utf8);
@ -227,7 +228,7 @@ private:
std::chrono::steady_clock::time_point m_last_rp_time = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point m_last_progress_message = std::chrono::steady_clock::now();
picojson::value m_ini_root;
Common::Lazy<picojson::value> m_ini_root{LoadApprovedList};
std::string m_game_ini_id;
std::unordered_map<AchievementId, LeaderboardStatus> m_leaderboard_map;