From 44d06ec42fc7ce0e24e9b0860cb5168c9754852c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 7 Jun 2025 16:35:19 +0200 Subject: [PATCH 1/3] Add some sanity checks guided by Android crash reports --- Common/Thread/Promise.h | 6 ++++-- Core/FileLoaders/ZipFileLoader.cpp | 2 +- Core/HLE/sceKernelModule.cpp | 6 +++--- Core/MIPS/MIPSAnalyst.cpp | 2 +- GPU/Common/DrawEngineCommon.h | 2 +- GPU/Software/SoftGpu.cpp | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Common/Thread/Promise.h b/Common/Thread/Promise.h index 19103f15e5..9a98ac1cab 100644 --- a/Common/Thread/Promise.h +++ b/Common/Thread/Promise.h @@ -164,9 +164,11 @@ public: void Cancel() { std::lock_guard guard(readyMutex_); if (!ready_) { - _dbg_assert_(task_); ready_ = true; - task_->Cancel(); + _dbg_assert_(task_); + if (task_) { + task_->Cancel(); + } rx_->Release(); rx_ = nullptr; } diff --git a/Core/FileLoaders/ZipFileLoader.cpp b/Core/FileLoaders/ZipFileLoader.cpp index bcf05907d0..c492f29eef 100644 --- a/Core/FileLoaders/ZipFileLoader.cpp +++ b/Core/FileLoaders/ZipFileLoader.cpp @@ -10,7 +10,7 @@ ZipFileLoader::ZipFileLoader(FileLoader *sourceLoader) : ProxiedFileLoader(sourceLoader), zipArchive_(nullptr) { if (!backend_ || !backend_->Exists() || backend_->IsDirectory()) { - // bad + return; } zip_error_t error{}; diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 59efa7e63e..84a17565f1 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -1323,10 +1323,10 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load bool insertSymbols = scan && !reader.LoadSymbols(); std::vector codeSections = reader.GetCodeSections(); for (SectionID id : codeSections) { - u32 start = reader.GetSectionAddr(id); + const u32 start = reader.GetSectionAddr(id); // Note: scan end is inclusive. - u32 end = start + reader.GetSectionSize(id) - 4; - u32 len = end + 4 - start; + const u32 end = start + reader.GetSectionSize(id) - 4; + const u32 len = end + 4 - start; if (len == 0) { // Seen in WWE: Smackdown vs Raw 2009. See #17435. continue; diff --git a/Core/MIPS/MIPSAnalyst.cpp b/Core/MIPS/MIPSAnalyst.cpp index 19876bbb52..4f456c5beb 100644 --- a/Core/MIPS/MIPSAnalyst.cpp +++ b/Core/MIPS/MIPSAnalyst.cpp @@ -1023,7 +1023,7 @@ skip: } bool ScanForFunctions(u32 startAddr, u32 endAddr, bool insertSymbols) { - _assert_(((startAddr | endAddr) & 3) == 0); + _assert_((startAddr & 3) == 0); std::lock_guard guard(functions_lock); diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index c535607b66..45a8b32bff 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -111,7 +111,7 @@ public: } void FlushSkin() { - if (dec_->skinInDecode) { + if (dec_ && dec_->skinInDecode) { FlushPartialDecode(); } } diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index f2e36bc00c..b9beca29a8 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -661,7 +661,7 @@ void SoftGPU::BeginHostFrame() { } bool SoftGPU::PresentedThisFrame() const { - return presentation_->PresentedThisFrame(); + return presentation_ ? presentation_->PresentedThisFrame() : false; } void SoftGPU::MarkDirty(uint32_t addr, uint32_t stride, uint32_t height, GEBufferFormat fmt, SoftGPUVRAMDirty value) { From 04684cc88b2aefa4856cea85040ca2d46a3fe879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 7 Jun 2025 17:18:51 +0200 Subject: [PATCH 2/3] Minor error message improvement --- Core/Util/PortManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/Util/PortManager.cpp b/Core/Util/PortManager.cpp index ac6b17d291..db92446a22 100644 --- a/Core/Util/PortManager.cpp +++ b/Core/Util/PortManager.cpp @@ -35,6 +35,7 @@ #include "Common/Thread/ThreadUtil.h" #include "Common/System/OSD.h" #include "Common/Log.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/Core.h" #include "Core/System.h" @@ -200,7 +201,7 @@ bool PortManager::Initialize(const unsigned int timeout) { ERROR_LOG(Log::sceNet, "PortManager - upnpDiscover failed (error: %i) or No UPnP device detected", error); if (g_Config.bEnableUPnP) { auto n = GetI18NCategory(I18NCat::NETWORKING); - g_OSD.Show(OSDType::MESSAGE_ERROR, n->T("Unable to find UPnP device")); + g_OSD.Show(OSDType::MESSAGE_ERROR, StringFromFormat("%s (%d)", n->T_cstr("Unable to find UPnP device"), error), 0.0f, "upnp_warning"); } m_InitState = UPNP_INITSTATE_NONE; #endif // WITH_UPNP From d00f8f940142b2a2a52fcd1d19fa44cd4bdf7abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 7 Jun 2025 17:43:18 +0200 Subject: [PATCH 3/3] Display: Don't clear display callback listeners when starting a new exec. Fixes https://github.com/RetroAchievements/RAIntegration/issues/1186 --- Core/HLE/sceDisplay.cpp | 3 +-- Core/HW/Display.cpp | 4 +++- Core/HW/Display.h | 1 + Core/System.cpp | 5 +++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index bfe6268a9d..aa2258f35d 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -175,7 +175,7 @@ static void ScheduleLagSync(int over = 0) { void __DisplayInit() { __DisplaySetFramerate(); - DisplayHWInit(); + DisplayHWReset(); hasSetMode = false; mode = 0; resumeMode = 0; @@ -296,7 +296,6 @@ void __DisplayDoState(PointerWrap &p) { } void __DisplayShutdown() { - DisplayHWShutdown(); vblankWaitingThreads.clear(); } diff --git a/Core/HW/Display.cpp b/Core/HW/Display.cpp index 573297f37f..064a2b1cde 100644 --- a/Core/HW/Display.cpp +++ b/Core/HW/Display.cpp @@ -308,7 +308,7 @@ int DisplayCalculateFrameSkip() { return frameSkipNum; } -void DisplayHWInit() { +void DisplayHWReset() { frameStartTicks = 0; numVBlanks = 0; isVblank = 0; @@ -329,6 +329,8 @@ void DisplayHWInit() { lastFrameTimeHistory = 0.0; } +void DisplayHWInit() {} + void DisplayHWShutdown() { std::lock_guard guard(listenersLock); vblankListeners.clear(); diff --git a/Core/HW/Display.h b/Core/HW/Display.h index a76a474b94..4bc08c1a45 100644 --- a/Core/HW/Display.h +++ b/Core/HW/Display.h @@ -55,5 +55,6 @@ void DisplayFireActualFlip(); int DisplayCalculateFrameSkip(); void DisplayHWInit(); +void DisplayHWReset(); void DisplayHWShutdown(); void DisplayHWDoState(PointerWrap &p, int hleCompatV2); diff --git a/Core/System.cpp b/Core/System.cpp index ce6d64fa13..fdc439e380 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -54,6 +54,7 @@ #include "Core/HLE/Plugins.h" #include "Core/HLE/ReplaceTables.h" #include "Core/HLE/sceKernel.h" +#include "Core/HW/Display.h" #include "Core/Config.h" #include "Core/Core.h" #include "Core/CoreTiming.h" @@ -409,6 +410,8 @@ static bool CPU_Init(FileLoader *fileLoader, IdentifiedFileType type, std::strin CoreTiming::Init(); + DisplayHWInit(); + // Init all the HLE modules HLEInit(); @@ -496,6 +499,8 @@ void CPU_Shutdown(bool success) { __KernelShutdown(); HLEShutdown(); + DisplayHWShutdown(); + pspFileSystem.Shutdown(); mipsr4k.Shutdown(); Memory::Shutdown();