From 0bf53e38f4c522f86800a1b8ab0bbf552b489701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 12 Nov 2024 11:08:47 +0100 Subject: [PATCH 1/4] Remove duplicated imgui keycode logging (already logs in the conversion function) --- ext/imgui/imgui_impl_platform.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ext/imgui/imgui_impl_platform.cpp b/ext/imgui/imgui_impl_platform.cpp index a9b9b8f170..f27bab8ca5 100644 --- a/ext/imgui/imgui_impl_platform.cpp +++ b/ext/imgui/imgui_impl_platform.cpp @@ -24,8 +24,6 @@ void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) { ImGuiKey keyCode = KeyCodeToImGui(key.keyCode); if (keyCode != ImGuiKey_None) { io.AddKeyEvent(keyCode, true); - } else { - WARN_LOG(Log::System, "KeyDown: Unmapped ImGui keycode conversion from %d", key.keyCode); } break; } @@ -35,8 +33,6 @@ void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) { ImGuiKey keyCode = KeyCodeToImGui(key.keyCode); if (keyCode != ImGuiKey_None) { io.AddKeyEvent(keyCode, false); - } else { - WARN_LOG(Log::System, "KeyUp: Unmapped ImGui keycode conversion from %d", key.keyCode); } } if (key.flags & KEY_CHAR) { From df104e7e317c20922bb0d57242087d4174ea5f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 12 Nov 2024 11:25:35 +0100 Subject: [PATCH 2/4] Fix crash due to null break reason --- Core/Core.cpp | 11 ++++++++--- .../WebSocket/SteppingBroadcaster.cpp | 6 ++++-- Core/PSPLoaders.cpp | 19 ++++++++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index c93b93eee4..22266804f6 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -415,13 +415,18 @@ bool Core_Run(GraphicsContext *ctx) { // Free-threaded (hm, possibly except tracing). void Core_Break(const char *reason, u32 relatedAddress) { // Stop the tracer - mipsTracer.stop_tracing(); - { std::lock_guard lock(g_stepMutex); + if (!g_stepCommand.empty()) { + // Already broke. + ERROR_LOG(Log::CPU, "Core_Break called with a break already in progress: %s", g_stepCommand.reason); + return; + } + mipsTracer.stop_tracing(); + g_stepCommand.reason = reason; + g_stepCommand.relatedAddr = relatedAddress; steppingCounter++; _assert_msg_(reason != nullptr, "No reason specified for break"); - Core_UpdateState(CORE_STEPPING); } System_Notify(SystemNotification::DEBUG_MODE_CHANGE); diff --git a/Core/Debugger/WebSocket/SteppingBroadcaster.cpp b/Core/Debugger/WebSocket/SteppingBroadcaster.cpp index 6e7e4aa71e..bbb17862fa 100644 --- a/Core/Debugger/WebSocket/SteppingBroadcaster.cpp +++ b/Core/Debugger/WebSocket/SteppingBroadcaster.cpp @@ -33,8 +33,10 @@ struct CPUSteppingEvent { j.writeUint("pc", currentMIPS->pc); // A double ought to be good enough for a 156 day debug session. j.writeFloat("ticks", CoreTiming::GetTicks()); - j.writeString("reason", reason_.reason); - j.writeUint("relatedAddress", reason_.relatedAddress); + if (reason_.reason) { + j.writeString("reason", reason_.reason); + j.writeUint("relatedAddress", reason_.relatedAddress); + } j.end(); return j.str(); } diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index c1e59d2f3b..57c8969d89 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -17,6 +17,7 @@ #include +#include "Core/Core.h" #include "Common/Data/Encoding/Utf8.h" #include "Common/Thread/ThreadUtil.h" #include "Common/System/Request.h" @@ -324,7 +325,11 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string) { // TODO: We can't use the initial error_string pointer. bool success = __KernelLoadExec(bootpath.c_str(), 0, &PSP_CoreParameter().errorString); if (success && coreState == CORE_POWERUP) { - coreState = PSP_CoreParameter().startBreak ? CORE_STEPPING : CORE_RUNNING; + if (PSP_CoreParameter().startBreak) { + Core_Break("start-break"); + } else { + coreState = CORE_RUNNING; + } } else { coreState = CORE_BOOT_ERROR; // TODO: This is a crummy way to communicate the error... @@ -483,7 +488,11 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) { bool success = __KernelLoadExec(finalName.c_str(), 0, &PSP_CoreParameter().errorString); if (success && coreState == CORE_POWERUP) { - coreState = PSP_CoreParameter().startBreak ? CORE_STEPPING : CORE_RUNNING; + if (PSP_CoreParameter().startBreak) { + Core_Break("start-break"); + } else { + coreState = CORE_RUNNING; + } } else { coreState = CORE_BOOT_ERROR; // TODO: This is a crummy way to communicate the error... @@ -509,7 +518,11 @@ bool Load_PSP_GE_Dump(FileLoader *fileLoader, std::string *error_string) { bool success = __KernelLoadGEDump("disc0:/data.ppdmp", &PSP_CoreParameter().errorString); if (success && coreState == CORE_POWERUP) { - coreState = PSP_CoreParameter().startBreak ? CORE_STEPPING : CORE_RUNNING; + if (PSP_CoreParameter().startBreak) { + Core_Break("start-break"); + } else { + coreState = CORE_RUNNING; + } } else { coreState = CORE_BOOT_ERROR; // TODO: This is a crummy way to communicate the error... From 39a07a033cc05df929f418cab3fa5f1dfc83d000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 12 Nov 2024 12:20:14 +0100 Subject: [PATCH 3/4] Make imdebugger visibility a config option instead of emuscreen state --- Core/Config.cpp | 1 + Core/Config.h | 2 ++ UI/EmuScreen.cpp | 40 +++++++++++++++++++++------------------- UI/EmuScreen.h | 1 - 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 14a8c98c7b..3792308eec 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -206,6 +206,7 @@ static const ConfigSetting generalSettings[] = { ConfigSetting("IgnoreBadMemAccess", &g_Config.bIgnoreBadMemAccess, true, CfgFlag::DEFAULT), ConfigSetting("CurrentDirectory", &g_Config.currentDirectory, "", CfgFlag::DEFAULT), ConfigSetting("ShowDebuggerOnLoad", &g_Config.bShowDebuggerOnLoad, false, CfgFlag::DEFAULT), + ConfigSetting("ShowImDebugger", &g_Config.bShowImDebugger, false, CfgFlag::DONT_SAVE), ConfigSetting("CheckForNewVersion", &g_Config.bCheckForNewVersion, true, CfgFlag::DEFAULT), ConfigSetting("Language", &g_Config.sLanguageIni, &DefaultLangRegion, CfgFlag::DEFAULT), ConfigSetting("ForceLagSync2", &g_Config.bForceLagSync, false, CfgFlag::PER_GAME), diff --git a/Core/Config.h b/Core/Config.h index 7055b09a78..801aadbdcb 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -190,6 +190,8 @@ public: bool bIgnoreScreenInsets; // Android: Center screen disregarding insets if this is enabled. bool bVSync; + bool bShowImDebugger; + int iFrameSkip; int iFrameSkipType; int iFastForwardMode; // See FastForwardMode in ConfigValues.h. diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 39e0fc23e3..b12bd1e4d6 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -656,7 +656,7 @@ bool EmuScreen::UnsyncTouch(const TouchInput &touch) { } } - if (!(imguiVisible_ && imguiInited_)) { + if (!(g_Config.bShowImDebugger && imguiInited_)) { GamepadTouch(); } @@ -673,7 +673,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) { switch (virtualKeyCode) { case VIRTKEY_TOGGLE_DEBUGGER: if (down) { - imguiVisible_ = !imguiVisible_; + g_Config.bShowImDebugger = !g_Config.bShowImDebugger; } break; case VIRTKEY_FASTFORWARD: @@ -952,10 +952,10 @@ void EmuScreen::onVKeyAnalog(int virtualKeyCode, float value) { bool EmuScreen::UnsyncKey(const KeyInput &key) { System_Notify(SystemNotification::ACTIVITY); - if (UI::IsFocusMovementEnabled() || (imguiVisible_ && imguiInited_)) { + if (UI::IsFocusMovementEnabled() || (g_Config.bShowImDebugger && imguiInited_)) { // Note: Allow some Vkeys through, so we can toggle the imgui for example (since we actually block the control mapper otherwise in imgui mode). // We need to manually implement it here :/ - if (imguiVisible_ && imguiInited_ && (key.flags & (KEY_UP | KEY_DOWN))) { + if (g_Config.bShowImDebugger && imguiInited_ && (key.flags & (KEY_UP | KEY_DOWN))) { InputMapping mapping(key.deviceId, key.keyCode); std::vector pspButtons; bool mappingFound = KeyMap::InputMappingToPspButton(mapping, &pspButtons); @@ -976,7 +976,7 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) { bool EmuScreen::key(const KeyInput &key) { bool retval = UIScreen::key(key); - if (!retval && imguiVisible_ && imguiInited_) { + if (!retval && g_Config.bShowImDebugger && imguiInited_) { ImGui_ImplPlatform_KeyEvent(key); } @@ -993,7 +993,7 @@ bool EmuScreen::key(const KeyInput &key) { } void EmuScreen::touch(const TouchInput &touch) { - if (imguiVisible_ && imguiInited_) { + if (g_Config.bShowImDebugger && imguiInited_) { ImGui_ImplPlatform_TouchEvent(touch); } else { UIScreen::touch(touch); @@ -1637,23 +1637,25 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) { darken(); } - if (imguiVisible_ && !imguiInited_) { - imguiInited_ = true; - imDebugger_ = std::make_unique(); - ImGui_ImplThin3d_Init(draw); - } + if (g_Config.bShowImDebugger) { + if (!imguiInited_) { + imguiInited_ = true; + imDebugger_ = std::make_unique(); + ImGui_ImplThin3d_Init(draw); + } - if (imguiVisible_ && imguiInited_ && PSP_IsInited()) { - _dbg_assert_(imDebugger_); + if (PSP_IsInited()) { + _dbg_assert_(imDebugger_); - ImGui_ImplPlatform_NewFrame(); - ImGui_ImplThin3d_NewFrame(draw, ui_draw2d.GetDrawMatrix()); + ImGui_ImplPlatform_NewFrame(); + ImGui_ImplThin3d_NewFrame(draw, ui_draw2d.GetDrawMatrix()); - ImGui::NewFrame(); - imDebugger_->Frame(currentDebugMIPS); + ImGui::NewFrame(); + imDebugger_->Frame(currentDebugMIPS); - ImGui::Render(); - ImGui_ImplThin3d_RenderDrawData(ImGui::GetDrawData(), draw); + ImGui::Render(); + ImGui_ImplThin3d_RenderDrawData(ImGui::GetDrawData(), draw); + } } return flags; } diff --git a/UI/EmuScreen.h b/UI/EmuScreen.h index 3200c633ff..d7bb7060e8 100644 --- a/UI/EmuScreen.h +++ b/UI/EmuScreen.h @@ -134,5 +134,4 @@ private: std::unique_ptr imDebugger_ = nullptr; bool imguiInited_ = false; - bool imguiVisible_ = false; }; From 18240b3ed015d7e91e5c35f4a5a49714e3aed63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 12 Nov 2024 11:30:01 +0100 Subject: [PATCH 4/4] Don't full-screen-on-doubleclick if ImGui debugger is active --- Windows/MainWindow.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index ab00f6c495..9e0368df2b 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -641,20 +641,20 @@ namespace MainWindow SetCapture(hWnd); // Simulate doubleclick, doesn't work with RawInput enabled - static double lastMouseDown; + static double lastMouseDownTime; static float lastMouseDownX = -1.0f; static float lastMouseDownY = -1.0f; - double now = time_now_d(); - if ((now - lastMouseDown) < 0.001 * GetDoubleClickTime()) { - float dx = lastMouseDownX - x; - float dy = lastMouseDownY - y; - float distSq = dx * dx + dy * dy; - if (distSq < 3.0f*3.0f && !g_Config.bShowTouchControls && !g_Config.bMouseControl && GetUIState() == UISTATE_INGAME && g_Config.bFullscreenOnDoubleclick) { + const double now = time_now_d(); + if ((now - lastMouseDownTime) < 0.001 * GetDoubleClickTime()) { + const float dx = lastMouseDownX - x; + const float dy = lastMouseDownY - y; + const float distSq = dx * dx + dy * dy; + if (distSq < 3.0f*3.0f && !g_Config.bShowTouchControls && !g_Config.bShowImDebugger && !g_Config.bMouseControl && GetUIState() == UISTATE_INGAME && g_Config.bFullscreenOnDoubleclick) { SendToggleFullscreen(!g_Config.UseFullScreen()); } - lastMouseDown = 0.0; + lastMouseDownTime = 0.0; } else { - lastMouseDown = now; + lastMouseDownTime = now; } lastMouseDownX = x; lastMouseDownY = y;