Skip to content

Commit 376a2e8

Browse files
committed
FullscreenUI: Fix crash when loading/saving state
Also fix fade transition.
1 parent 33b1e82 commit 376a2e8

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/core/fullscreen_ui.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ static bool AreAnyDialogsOpen();
238238
static void ClosePauseMenu();
239239
static void ClosePauseMenuImmediately();
240240
static void SwitchToMainWindow(MainWindowType type);
241+
static void ReturnToMainWindow(float transition_time = GPUThread::HasGPUBackend() ? SHORT_TRANSITION_TIME :
242+
DEFAULT_TRANSITION_TIME);
241243
static void DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size);
242244
static void DrawLandingWindow();
243245
static void DrawStartGameWindow();
@@ -1191,12 +1193,12 @@ void FullscreenUI::ReturnToPreviousWindow()
11911193
}
11921194
}
11931195

1194-
void FullscreenUI::ReturnToMainWindow()
1196+
void FullscreenUI::ReturnToMainWindow(
1197+
float transition_time /* = GPUThread::HasGPUBackend() ? SHORT_TRANSITION_TIME : DEFAULT_TRANSITION_TIME */)
11951198
{
11961199
if (GPUThread::IsSystemPaused() && !s_state.was_paused_on_quick_menu_open)
11971200
Host::RunOnCPUThread([]() { System::PauseSystem(false); });
11981201

1199-
const float transition_time = GPUThread::HasGPUBackend() ? SHORT_TRANSITION_TIME : DEFAULT_TRANSITION_TIME;
12001202
BeginTransition(transition_time, []() {
12011203
s_state.previous_main_window = MainWindowType::None;
12021204
s_state.current_pause_submenu = PauseSubMenu::None;
@@ -7366,7 +7368,7 @@ void FullscreenUI::DrawSaveStateSelector()
73667368

73677369
if (GPUThread::HasGPUBackend())
73687370
{
7369-
ReturnToMainWindow();
7371+
ReturnToMainWindow(LONG_TRANSITION_TIME);
73707372

73717373
Host::RunOnCPUThread([game_path = std::move(game_path), state_path = std::move(state_path)]() mutable {
73727374
if (System::IsValid())
@@ -7401,7 +7403,7 @@ void FullscreenUI::DrawSaveStateSelector()
74017403

74027404
static constexpr auto do_save_state = [](s32 slot, bool global) {
74037405
ClearSaveStateEntryList();
7404-
ReturnToMainWindow();
7406+
ReturnToMainWindow(LONG_TRANSITION_TIME);
74057407

74067408
Host::RunOnCPUThread([slot, global]() {
74077409
if (!System::IsValid())
@@ -7422,7 +7424,7 @@ void FullscreenUI::DrawSaveStateSelector()
74227424
ImGuiIO& io = ImGui::GetIO();
74237425
const ImVec2 heading_size = ImVec2(
74247426
io.DisplaySize.x, UIStyle.LargeFontSize + (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f));
7425-
7427+
SaveStateListEntry* pressed_entry = nullptr;
74267428
bool closed = false;
74277429

74287430
// last state deleted?
@@ -7535,12 +7537,8 @@ void FullscreenUI::DrawSaveStateSelector()
75357537

75367538
if (pressed)
75377539
{
7538-
if (s_state.save_state_selector_loading)
7539-
do_load_state(std::move(entry.game_path), std::move(entry.state_path));
7540-
else
7541-
do_save_state(entry.slot, entry.global);
7542-
7543-
closed = true;
7540+
// avoid closing while drawing
7541+
pressed_entry = &entry;
75447542
}
75457543
else if (hovered &&
75467544
(ImGui::IsItemClicked(ImGuiMouseButton_Right) ||
@@ -7652,7 +7650,14 @@ void FullscreenUI::DrawSaveStateSelector()
76527650
GetBackgroundAlpha());
76537651
}
76547652

7655-
if ((!AreAnyDialogsOpen() && WantsToCloseMenu()) || closed)
7653+
if (pressed_entry)
7654+
{
7655+
if (s_state.save_state_selector_loading)
7656+
do_load_state(std::move(pressed_entry->game_path), std::move(pressed_entry->state_path));
7657+
else
7658+
do_save_state(pressed_entry->slot, pressed_entry->global);
7659+
}
7660+
else if ((!AreAnyDialogsOpen() && WantsToCloseMenu()) || closed)
76567661
{
76577662
ClearSaveStateEntryList();
76587663
ReturnToPreviousWindow();

src/core/fullscreen_ui.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ void OpenCheatsMenu();
7979
void OpenDiscChangeMenu();
8080
void OpenAchievementsWindow();
8181
void OpenLeaderboardsWindow();
82-
void ReturnToMainWindow();
8382
void ReturnToPreviousWindow();
8483
void SetStandardSelectionFooterText(bool back_instead_of_cancel);
8584

0 commit comments

Comments
 (0)