Skip to content

Commit

Permalink
Achievements: Fix race condition invalidating images
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 13, 2025
1 parent 2f854de commit 8f39dbb
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/core/achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void BeginLoadGame();
static void BeginChangeDisc();
static void UpdateGameSummary();
static std::string GetLocalImagePath(const std::string_view image_name, int type);
static void DownloadImage(std::string url, std::string cache_filename);
static void DownloadImage(std::string url, std::string cache_path);
static void UpdateGlyphRanges();

static TinyString DecryptLoginToken(std::string_view encrypted_token, std::string_view username);
Expand Down Expand Up @@ -370,23 +370,25 @@ std::string Achievements::GetLocalImagePath(const std::string_view image_name, i
return ret;
}

void Achievements::DownloadImage(std::string url, std::string cache_filename)
void Achievements::DownloadImage(std::string url, std::string cache_path)
{
auto callback = [cache_filename](s32 status_code, const Error& error, const std::string& content_type,
HTTPDownloader::Request::Data data) {
auto callback = [cache_path = std::move(cache_path)](s32 status_code, const Error& error,
const std::string& content_type,
HTTPDownloader::Request::Data data) mutable {
if (status_code != HTTPDownloader::HTTP_STATUS_OK)
{
ERROR_LOG("Failed to download badge '{}': {}", Path::GetFileName(cache_filename), error.GetDescription());
ERROR_LOG("Failed to download badge '{}': {}", Path::GetFileName(cache_path), error.GetDescription());
return;
}

if (!FileSystem::WriteBinaryFile(cache_filename.c_str(), data.data(), data.size()))
if (!FileSystem::WriteBinaryFile(cache_path.c_str(), data.data(), data.size()))
{
ERROR_LOG("Failed to write badge image to '{}'", cache_filename);
ERROR_LOG("Failed to write badge image to '{}'", cache_path);
return;
}

ImGuiFullscreen::InvalidateCachedTexture(cache_filename);
GPUThread::RunOnThread(
[cache_path = std::move(cache_path)]() { ImGuiFullscreen::InvalidateCachedTexture(cache_path); });
};

s_state.http_downloader->CreateRequest(std::move(url), std::move(callback));
Expand Down

0 comments on commit 8f39dbb

Please sign in to comment.