Skip to content

Commit

Permalink
FullscreenUI: Fix CPU/GPU thread race on achievements toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Dec 21, 2024
1 parent 26db661 commit 6b754e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
21 changes: 12 additions & 9 deletions src/core/achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2185,12 +2185,7 @@ void Achievements::ConfirmHardcoreModeDisableAsync(const char* trigger, std::fun

void Achievements::ClearUIState()
{
#ifndef __ANDROID__
if (FullscreenUI::IsAchievementsWindowOpen() || FullscreenUI::IsLeaderboardsWindowOpen())
FullscreenUI::ReturnToPreviousWindow();

CloseLeaderboard();
#endif

s_state.achievement_badge_paths = {};

Expand Down Expand Up @@ -2470,10 +2465,14 @@ void Achievements::DrawAchievementsWindow()
using ImGuiFullscreen::LayoutScale;
using ImGuiFullscreen::UIStyle;

auto lock = Achievements::GetLock();

// achievements can get turned off via the main UI
if (!s_state.achievement_list)
{
FullscreenUI::ReturnToPreviousWindow();
return;

auto lock = Achievements::GetLock();
}

static constexpr float alpha = 0.8f;
static constexpr float heading_alpha = 0.95f;
Expand Down Expand Up @@ -2846,7 +2845,12 @@ void Achievements::DrawLeaderboardsWindow()
static constexpr float heading_height_unscaled = 110.0f;
static constexpr float tab_height_unscaled = 50.0f;

auto lock = Achievements::GetLock();
const auto lock = Achievements::GetLock();
if (!s_state.leaderboard_list)
{
FullscreenUI::ReturnToPreviousWindow();
return;
}

const bool is_leaderboard_open = (s_state.open_leaderboard != nullptr);
bool close_leaderboard_on_exit = false;
Expand Down Expand Up @@ -3437,7 +3441,6 @@ void Achievements::CloseLeaderboard()
}

s_state.open_leaderboard = nullptr;
ImGuiFullscreen::QueueResetFocus(ImGuiFullscreen::FocusResetType::Other);
}

#if defined(_WIN32)
Expand Down
30 changes: 1 addition & 29 deletions src/core/fullscreen_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,25 +634,7 @@ bool FullscreenUI::AreAnyDialogsOpen()

void FullscreenUI::CheckForConfigChanges(const Settings& old_settings)
{
// NOTE: Called on CPU thread.
if (!IsInitialized())
return;

// If achievements got disabled, we might have the menu open...
// That means we're going to be reading achievement state.
if (old_settings.achievements_enabled && !g_settings.achievements_enabled)
{
if (!IsInitialized())
return;

GPUThread::RunOnThread([]() {
if (s_state.current_main_window == MainWindowType::Achievements ||
s_state.current_main_window == MainWindowType::Leaderboards)
{
ReturnToPreviousWindow();
}
});
}
// NOTE: Called on GPU thread.
}

void FullscreenUI::UpdateRunIdleState()
Expand Down Expand Up @@ -7635,11 +7617,6 @@ void FullscreenUI::OpenAchievementsWindow()
});
}

bool FullscreenUI::IsAchievementsWindowOpen()
{
return (s_state.current_main_window == MainWindowType::Achievements);
}

void FullscreenUI::OpenLeaderboardsWindow()
{
if (!System::IsValid())
Expand Down Expand Up @@ -7674,11 +7651,6 @@ void FullscreenUI::OpenLeaderboardsWindow()
});
}

bool FullscreenUI::IsLeaderboardsWindowOpen()
{
return (s_state.current_main_window == MainWindowType::Leaderboards);
}

#endif // __ANDROID__

LoadingScreenProgressCallback::LoadingScreenProgressCallback()
Expand Down
2 changes: 0 additions & 2 deletions src/core/fullscreen_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ void OnRunningGameChanged();
void OpenPauseMenu();
void OpenCheatsMenu();
void OpenAchievementsWindow();
bool IsAchievementsWindowOpen();
void OpenLeaderboardsWindow();
bool IsLeaderboardsWindowOpen();
void ReturnToMainWindow();
void ReturnToPreviousWindow();
void SetStandardSelectionFooterText(bool back_instead_of_cancel);
Expand Down

0 comments on commit 6b754e6

Please sign in to comment.