From bebcec831441927d3b2cf65a11cd6cbb6815c685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 24 Apr 2025 08:52:14 +0200 Subject: [PATCH] EmuScreen: Clarify some logic, add some checks --- Common/UI/View.cpp | 2 +- Core/HLE/sceKernel.cpp | 5 ++--- Core/System.cpp | 2 +- UI/EmuScreen.cpp | 51 +++++++++++++++++++++++++----------------- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 299a48b29f..f188102339 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -100,7 +100,7 @@ View::~View() { RemoveQueuedEventsByView(this); // Could use unique_ptr, but then we have to include tween everywhere. - for (auto &tween : tweens_) + for (UI::Tween *tween : tweens_) delete tween; } diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 4b691d9631..a20ba965a2 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -180,9 +180,8 @@ void __KernelInit() void __KernelShutdown() { - if (!kernelRunning) - { - ERROR_LOG(Log::sceKernel, "Can't shut down kernel - not running"); + if (!kernelRunning) { + INFO_LOG(Log::sceKernel, "Can't shut down kernel - not running"); return; } kernelObjects.List(); diff --git a/Core/System.cpp b/Core/System.cpp index fd976a4b23..5c4b9f5d51 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -530,7 +530,7 @@ bool PSP_InitStart(const CoreParameter &coreParam) { INFO_LOG(Log::Loader, "Starting loader thread..."); - _dbg_assert_(!g_loadingThread.joinable()); + _assert_msg_(!g_loadingThread.joinable(), "%s", coreParam.fileToStart.c_str()); g_loadingThread = std::thread([error_string]() { SetCurrentThreadName("ExecLoader"); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index fa00cb48a7..5dd1e98584 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -243,11 +243,21 @@ bool EmuScreen::bootAllowStorage(const Path &filename) { } void EmuScreen::ProcessGameBoot(const Path &filename) { + if (!bootPending_) { + // Nothing to do. + return; + } + if (Achievements::IsBlockingExecution()) { // Keep waiting. return; } + // Check permission status first, in case we came from a shortcut. + if (!bootAllowStorage(filename)) { + return; + } + std::string error_string = "(unknown error)"; BootState state = PSP_InitUpdate(&error_string); @@ -287,10 +297,6 @@ void EmuScreen::ProcessGameBoot(const Path &filename) { break; } - // Check permission status first, in case we came from a shortcut. - if (!bootAllowStorage(filename)) - return; - SetAssertCancelCallback(&AssertCancelCallback, this); currentMIPS = &mipsr4k; @@ -345,6 +351,9 @@ void EmuScreen::ProcessGameBoot(const Path &filename) { return; } + _dbg_assert_(loadingViewVisible_); + _dbg_assert_(loadingViewColor_); + if (loadingViewColor_) loadingViewColor_->Divert(0xFFFFFFFF, 0.75f); if (loadingViewVisible_) @@ -352,9 +361,7 @@ void EmuScreen::ProcessGameBoot(const Path &filename) { screenManager()->getDrawContext()->ResetStats(); - if (bootPending_) { - System_PostUIMessage(UIMessage::GAME_SELECTED, filename.c_str()); - } + System_PostUIMessage(UIMessage::GAME_SELECTED, filename.c_str()); } // Only call this on successful boot. @@ -433,10 +440,8 @@ void EmuScreen::bootComplete() { saveStateSlot_ = SaveState::GetCurrentSlot(); - if (loadingViewColor_) - loadingViewColor_->Divert(0x00FFFFFF, 0.2f); - if (loadingViewVisible_) - loadingViewVisible_->Divert(UI::V_INVISIBLE, 0.2f); + loadingViewColor_->Divert(0x00FFFFFF, 0.2f); + loadingViewVisible_->Divert(UI::V_INVISIBLE, 0.2f); std::string gameID = g_paramSFO.GetValueString("DISC_ID"); g_Config.TimeTracker().Start(gameID); @@ -494,6 +499,7 @@ void EmuScreen::dialogFinished(const Screen *dialog, DialogResult result) { // DR_CANCEL/DR_BACK means clicked on "continue", DR_OK means clicked on "back to menu", // DR_YES means a message sent to PauseMenu by System_PostUIMessage. if (result == DR_OK || quit_) { + _dbg_assert_(!bootPending_); screenManager()->switchScreen(new MainScreen()); quit_ = false; } @@ -540,8 +546,13 @@ void EmuScreen::focusChanged(ScreenFocusChange focusChange) { void EmuScreen::sendMessage(UIMessage message, const char *value) { // External commands, like from the Windows UI. + // This happens on the main thread. if (message == UIMessage::REQUEST_GAME_PAUSE && screenManager()->topScreen() == this) { - screenManager()->push(new GamePauseScreen(gamePath_)); + if (!bootPending_) { + screenManager()->push(new GamePauseScreen(gamePath_)); + } else { + ERROR_LOG(Log::Loader, "Can't pause during pending boot"); + } } else if (message == UIMessage::REQUEST_GAME_STOP) { // We will push MainScreen in update(). if (bootPending_) { @@ -716,7 +727,7 @@ void EmuScreen::onVKey(VirtKey virtualKeyCode, bool down) { } break; case VIRTKEY_FASTFORWARD: - if (down && !NetworkWarnUserIfOnlineAndCantSpeed()) { + if (down && !NetworkWarnUserIfOnlineAndCantSpeed() && !bootPending_) { /* // This seems like strange behavior. Commented it out. if (coreState == CORE_STEPPING_CPU) { @@ -831,7 +842,7 @@ void EmuScreen::onVKey(VirtKey virtualKeyCode, bool down) { #endif case VIRTKEY_REWIND: - if (down && !Achievements::WarnUserIfHardcoreModeActive(false) && !NetworkWarnUserIfOnlineAndCantSavestate()) { + if (down && !Achievements::WarnUserIfHardcoreModeActive(false) && !NetworkWarnUserIfOnlineAndCantSavestate() && !bootPending_) { if (SaveState::CanRewind()) { SaveState::Rewind(&AfterSaveStateAction); } else { @@ -840,12 +851,12 @@ void EmuScreen::onVKey(VirtKey virtualKeyCode, bool down) { } break; case VIRTKEY_SAVE_STATE: - if (down && !Achievements::WarnUserIfHardcoreModeActive(true) && !NetworkWarnUserIfOnlineAndCantSavestate()) { + if (down && !Achievements::WarnUserIfHardcoreModeActive(true) && !NetworkWarnUserIfOnlineAndCantSavestate() && !bootPending_) { SaveState::SaveSlot(gamePath_, g_Config.iCurrentStateSlot, &AfterSaveStateAction); } break; case VIRTKEY_LOAD_STATE: - if (down && !Achievements::WarnUserIfHardcoreModeActive(false) && !NetworkWarnUserIfOnlineAndCantSavestate()) { + if (down && !Achievements::WarnUserIfHardcoreModeActive(false) && !NetworkWarnUserIfOnlineAndCantSavestate() && !bootPending_) { SaveState::LoadSlot(gamePath_, g_Config.iCurrentStateSlot, &AfterSaveStateAction); } break; @@ -1508,11 +1519,9 @@ void EmuScreen::darken() { ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) { // Moved from update, because we want it to be possible for booting to happen even when the screen // is in the background, like when choosing Reset from the pause menu. - if (bootPending_) { - // Keep trying the boot until bootPending_ is lifted. - // It may be delayed due to RetroAchievements or any other cause. - ProcessGameBoot(gamePath_); - } + + // If a boot is in progress, update it. + ProcessGameBoot(gamePath_); ScreenRenderFlags flags = ScreenRenderFlags::NONE; Draw::Viewport viewport{ 0.0f, 0.0f, (float)g_display.pixel_xres, (float)g_display.pixel_yres, 0.0f, 1.0f };