From 1cf65ab6a415bbe7929c8aa8bc6283153ad94ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 19 Oct 2026 09:10:03 +0200 Subject: [PATCH] Clarify comments from the crash fixes Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/HLE/sceNetAdhocMatching.cpp | 5 ++--- Core/System.cpp | 6 +++--- Core/System.h | 6 +++--- UI/EmuScreen.cpp | 11 +++++------ UI/NativeApp.cpp | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Core/HLE/sceNetAdhocMatching.cpp b/Core/HLE/sceNetAdhocMatching.cpp index ba9ed84c22..b28bad96d3 100644 --- a/Core/HLE/sceNetAdhocMatching.cpp +++ b/Core/HLE/sceNetAdhocMatching.cpp @@ -1614,9 +1614,8 @@ int sceNetAdhocMatchingStop(int matchingId) { } int NetAdhocMatching_Delete(int matchingId) { - // Stop it first if it's still running. Not under peerlock, since Stop joins the matching threads, which take it. - // And not after unlinking it below, where Stop can't find it - which leaves the threads running, and - // deleting their std::threads calls std::terminate. + // Running threads can't be deleted, so stop them first. This has to happen before we take peerlock, + // since the threads take it too. SceNetAdhocMatchingContext *item = findMatchingContext(matchingId); if (item && item->running) { NetAdhocMatching_Stop(matchingId); diff --git a/Core/System.cpp b/Core/System.cpp index b0be410198..9ff829ced0 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -840,7 +840,7 @@ bool PSP_InitStart(const CoreParameter &coreParam) { // CPU_Shutdown(), so PSP_InitUpdate would take the success path on a core that no longer // exists, right down to a null Memory::base. { - // Held while creating the GPU, so the device can't be lost meanwhile. + // Keeps the device from being lost while we create the GPU. std::lock_guard lock(g_graphicsDeviceMutex); if (!g_graphicsDeviceLost && !InitGPU(errorString)) { return; @@ -876,12 +876,12 @@ BootState PSP_InitUpdate(std::string *error_string) { return BootState::Failed; } - // On libretro, and if the graphics device was lost when the boot thread got there, the GPU is created here. + // Create the GPU here if the boot thread didn't (always on libretro, otherwise when the device was lost). if (!gpu) { std::lock_guard lock(g_graphicsDeviceMutex); bool success; if (g_graphicsDeviceLost) { - // Exiting during boot, with the device gone. + // We're exiting during boot, and there's no device to create the GPU on. g_CoreParameter.errorString = "Graphics device lost during boot"; CPU_Shutdown(false); success = false; diff --git a/Core/System.h b/Core/System.h index c1225ec462..c3bbefe30e 100644 --- a/Core/System.h +++ b/Core/System.h @@ -78,9 +78,9 @@ BootState PSP_Init(const CoreParameter &coreParam, std::string *error_string); // The main thread needs to block on this in some situations, like losing the surface. BootState PollBootState(); -// The boot thread creates the GPU at the end of a boot. If the graphics device is lost then (like when the -// Android app is in the background), it leaves that to PSP_InitUpdate, which runs once rendering resumes. -// Lost waits for a GPU creation in progress to finish, so the GPU can be told about the loss. +// The boot thread creates the GPU at the end of a boot. If the graphics device is lost at that point (like +// when the Android app is in the background), PSP_InitUpdate creates it instead, once rendering resumes. +// If the boot thread is creating the GPU when the device is lost, Lost waits for it to finish. void PSP_NotifyGraphicsDeviceLost(); void PSP_NotifyGraphicsDeviceRestored(); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 57d6fc4569..ef7ca07708 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -455,9 +455,8 @@ EmuScreen::~EmuScreen() { g_Config.TimeTracker().Stop(gameID); if (bootPending_) { - // We quit during boot (maybe from the background, without the graphics device coming back), - // and didn't end up in update again to call PSP_InitUpdate. So we need to finish and join the - // boot thread before we can exit. + // We quit during boot (maybe from the background), before update called PSP_InitUpdate. + // Wait for the boot thread to finish, so PSP_InitUpdate can join it. while (PollBootState() == BootState::Booting) { sleep_ms(10, "exit-during-boot"); } @@ -1599,9 +1598,9 @@ bool EmuScreen::ShouldRunEmulation(ScreenRenderMode mode) const { return true; } -// The GPU only picks up a changed Skip Buffer Effects setting in BeginHostFrame, so while emulation -// isn't running (like in the pause menu) it can still be in non-buffered mode. There, it draws straight -// into the backbuffer pass, which isn't bound yet in PreRender. +// The GPU only applies a changed Skip Buffer Effects setting in BeginHostFrame, so while emulation is +// paused it can still be in non-buffered mode. Then it draws directly to the backbuffer, which isn't +// bound yet in PreRender. static bool GPUIsBuffered() { FramebufferManagerCommon *framebufferManager = gpu->GetFramebufferManagerCommon(); return !framebufferManager || framebufferManager->UseBufferedRendering(); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 2a223794c8..103a7718ca 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -978,7 +978,7 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) { ImGui_ImplThin3d_CreateDeviceObjects(g_draw); } - // Last, so that a GPU the boot thread creates from now on doesn't also get the DeviceRestore above. + // Last, since a GPU the boot thread creates after this must not also get the DeviceRestore above. PSP_NotifyGraphicsDeviceRestored(); #if !PPSSPP_PLATFORM(UWP) @@ -1046,7 +1046,7 @@ bool CreateGlobalPipelines() { void NativeShutdownGraphics(GraphicsContext *graphicsContext) { INFO_LOG(Log::System, "NativeShutdownGraphics begin"); - // First, so that a boot that's creating its GPU finishes that before the DeviceLost calls below. + // First, since this waits for a GPU the boot thread is creating, which then gets the DeviceLost calls below. PSP_NotifyGraphicsDeviceLost(); #if !PPSSPP_PLATFORM(UWP)