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] 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) {