From 662b0847c9e14aed9d416be51eff785b34f22fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Oct 2024 14:56:20 +0200 Subject: [PATCH 1/7] Assert instead of crashing if demo ISO decryption fails --- Core/FileSystems/BlockDevices.cpp | 128 +++++++++++++++--------------- Core/FileSystems/BlockDevices.h | 28 ++++--- 2 files changed, 79 insertions(+), 77 deletions(-) diff --git a/Core/FileSystems/BlockDevices.cpp b/Core/FileSystems/BlockDevices.cpp index 4b2d72ccaa..1e7dd8402c 100644 --- a/Core/FileSystems/BlockDevices.cpp +++ b/Core/FileSystems/BlockDevices.cpp @@ -37,8 +37,6 @@ extern "C" #include "ext/libkirk/kirk_engine.h" }; -std::mutex NPDRMDemoBlockDevice::mutex_; - BlockDevice *constructBlockDevice(FileLoader *fileLoader) { if (!fileLoader->Exists()) { return nullptr; @@ -389,8 +387,7 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader) MAC_KEY mkey; CIPHER_KEY ckey; u8 np_header[256]; - u32 tableOffset, tableSize; - u32 lbaStart, lbaEnd; + u32 tableOffset_, tableSize_; fileLoader_->ReadAt(0x24, 1, 4, &psarOffset); size_t readSize = fileLoader_->ReadAt(psarOffset, 1, 256, &np_header); @@ -411,29 +408,38 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader) sceDrmBBCipherUpdate(&ckey, np_header+0x40, 0x60); sceDrmBBCipherFinal(&ckey); - lbaStart = *(u32*)(np_header+0x54); // LBA start - lbaEnd = *(u32*)(np_header+0x64); // LBA end - lbaSize = (lbaEnd-lbaStart+1); // LBA size of ISO - blockLBAs = *(u32*)(np_header+0x0c); // block size in LBA - blockSize = blockLBAs*2048; - numBlocks = (lbaSize+blockLBAs-1)/blockLBAs; // total blocks; + u32 lbaStart = *(u32*)(np_header+0x54); // LBA start + u32 lbaEnd = *(u32*)(np_header+0x64); // LBA end + lbaSize_ = (lbaEnd-lbaStart+1); // LBA size of ISO + blockLBAs_ = *(u32*)(np_header+0x0c); // block size in LBA - blockBuf = new u8[blockSize]; - tempBuf = new u8[blockSize]; + // Protect against a badly decrypted header, and send information through the assert about what's being played (implicitly). + _assert_msg_(blockLBAs_ <= 4096, "Bad blockLBAs in header: %08x (%s)", blockLBAs_, fileLoader->GetPath().ToVisualString().c_str()); - tableOffset = *(u32*)(np_header+0x6c); // table offset + // When we remove the above assert, let's just try to survive. + if (blockLBAs_ > 4096) { + return; + } - tableSize = numBlocks*32; - table = new table_info[numBlocks]; + blockSize_ = blockLBAs_ * 2048; + numBlocks_ = (lbaSize_ + blockLBAs_-1) / blockLBAs_; // total blocks; - readSize = fileLoader_->ReadAt(psarOffset + tableOffset, 1, tableSize, table); - if(readSize!=tableSize){ + blockBuf_ = new u8[blockSize_]; + tempBuf_ = new u8[blockSize_]; + + tableOffset_ = *(u32*)(np_header+0x6c); // table offset + + tableSize_ = numBlocks_ * 32; + table_ = new table_info[numBlocks_]; + + readSize = fileLoader_->ReadAt(psarOffset + tableOffset_, 1, tableSize_, table_); + if (readSize!=tableSize_){ ERROR_LOG(Log::Loader, "Invalid NPUMDIMG table!"); } - u32 *p = (u32*)table; + u32 *p = (u32*)table_; u32 i, k0, k1, k2, k3; - for(i=0; i guard(mutex_); - delete [] table; - delete [] tempBuf; - delete [] blockBuf; + delete [] table_; + delete [] tempBuf_; + delete [] blockBuf_; } int lzrc_decompress(void *out, int out_len, void *in, int in_len); -bool NPDRMDemoBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached) -{ +bool NPDRMDemoBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached) { FileLoader::Flags flags = uncached ? FileLoader::Flags::HINT_UNCACHED : FileLoader::Flags::NONE; std::lock_guard guard(mutex_); - CIPHER_KEY ckey; - int block, lba, lzsize; - size_t readSize; - u8 *readBuf; - lba = blockNumber-currentBlock; - if(lba>=0 && lba= 0 && lba < blockLBAs_){ + memcpy(outPtr, blockBuf_ + lba*2048, 2048); return true; } - block = blockNumber/blockLBAs; - lba = blockNumber%blockLBAs; - currentBlock = block*blockLBAs; + int block = blockNumber / blockLBAs_; + lba = blockNumber % blockLBAs_; + currentBlock_ = block * blockLBAs_; - if(table[block].unk_1c!=0){ - if((u32)block==(numBlocks-1)) + if (table_[block].unk_1c != 0) { + if((u32)block == (numBlocks_ - 1)) return true; // demos make by fake_np else return false; } - if(table[block].sizeReadAt(psarOffset+table[block].offset, 1, table[block].size, readBuf, flags); - if(readSize != (size_t)table[block].size){ - if((u32)block==(numBlocks-1)) + size_t readSize = fileLoader_->ReadAt(psarOffset+table_[block].offset, 1, table_[block].size, readBuf, flags); + if (readSize != (size_t)table_[block].size){ + if((u32)block==(numBlocks_-1)) return true; else return false; } - if((table[block].flag&1)==0){ + if ((table_[block].flag & 1) == 0) { // skip mac check } - if((table[block].flag&4)==0){ - sceDrmBBCipherInit(&ckey, 1, 2, hkey, vkey, table[block].offset>>4); - sceDrmBBCipherUpdate(&ckey, readBuf, table[block].size); + if ((table_[block].flag & 4) == 0) { + CIPHER_KEY ckey; + sceDrmBBCipherInit(&ckey, 1, 2, hkey, vkey, table_[block].offset>>4); + sceDrmBBCipherUpdate(&ckey, readBuf, table_[block].size); sceDrmBBCipherFinal(&ckey); } - if(table[block].sizeGetPath(); int depth = 0; @@ -650,16 +652,14 @@ CHDFileBlockDevice::CHDFileBlockDevice(FileLoader *fileLoader) numBlocks = impl_->header->unitcount; } -CHDFileBlockDevice::~CHDFileBlockDevice() -{ +CHDFileBlockDevice::~CHDFileBlockDevice() { if (impl_->chd) { chd_close(impl_->chd); delete[] readBuffer; } } -bool CHDFileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached) -{ +bool CHDFileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached) { if (!impl_->chd) { ERROR_LOG(Log::Loader, "ReadBlock: CHD not open. %s", fileLoader_->GetPath().c_str()); return false; diff --git a/Core/FileSystems/BlockDevices.h b/Core/FileSystems/BlockDevices.h index 3885e336fa..27f4b9ddbf 100644 --- a/Core/FileSystems/BlockDevices.h +++ b/Core/FileSystems/BlockDevices.h @@ -113,25 +113,27 @@ public: ~NPDRMDemoBlockDevice(); bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) override; - u32 GetNumBlocks() const override {return (u32)lbaSize;} + u32 GetNumBlocks() const override {return (u32)lbaSize_;} bool IsDisc() const override { return false; } private: - static std::mutex mutex_; - u32 lbaSize; + // TODO: Doubt this mutex is actually needed. + std::mutex mutex_; - u32 psarOffset; - int blockSize; - int blockLBAs; - u32 numBlocks; + u32 lbaSize_ = 0; - u8 vkey[16]; - u8 hkey[16]; - struct table_info *table; + u32 psarOffset = 0; + int blockSize_ = 0; + int blockLBAs_ = 0; + u32 numBlocks_ = 0; - int currentBlock; - u8 *blockBuf; - u8 *tempBuf; + u8 vkey[16]{}; + u8 hkey[16]{}; + struct table_info *table_ = nullptr; + + int currentBlock_ = 0; + u8 *blockBuf_ = nullptr; + u8 *tempBuf_ = nullptr; }; struct CHDImpl; From bf9973e17d7f57bc4ee032bb2e44da0f3c62e86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Oct 2024 14:36:43 +0200 Subject: [PATCH 2/7] =?UTF-8?q?GameScreen=20=C4=87rc-related=20crashfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UI/GameScreen.cpp | 78 +++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index 14a71400f0..cf16615387 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -80,8 +80,10 @@ void GameScreen::update() { if (Reporting::HasCRC(gamePath_)) { uint32_t crcvalue = Reporting::RetrieveCRC(gamePath_); CRC32string = int2hexstr(crcvalue); - tvCRC_->SetVisibility(UI::V_VISIBLE); - tvCRC_->SetText(CRC32string); + if (tvCRC_) { + tvCRC_->SetVisibility(UI::V_VISIBLE); + tvCRC_->SetText(CRC32string); + } if (tvCRCCopy_) { tvCRCCopy_->SetVisibility(UI::V_VISIBLE); } @@ -114,6 +116,21 @@ void GameScreen::CreateViews() { ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0f)); root_->Add(leftColumn); + bool fileTypeSupportCRC = false; + if (info) { + switch (info->fileType) { + case IdentifiedFileType::PSP_PBP: + case IdentifiedFileType::PSP_PBP_DIRECTORY: + case IdentifiedFileType::PSP_ISO_NP: + case IdentifiedFileType::PSP_ISO: + fileTypeSupportCRC = true; + break; + + default: + break; + } + } + leftColumn->Add(new Choice(di->T("Back"), "", false, new AnchorLayoutParams(150, WRAP_CONTENT, 10, NONE, NONE, 10)))->OnClick.Handle(this, &GameScreen::OnSwitchBack); if (info->Ready(GameInfoFlags::PARAM_SFO)) { ViewGroup *badgeHolder = new LinearLayout(ORIENT_HORIZONTAL, new AnchorLayoutParams(10, 10, 110, NONE)); @@ -151,25 +168,29 @@ void GameScreen::CreateViews() { tvPlayTime_->SetVisibility(V_GONE); LinearLayout *crcHoriz = infoLayout->Add(new LinearLayout(ORIENT_HORIZONTAL)); - tvCRC_ = crcHoriz->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(0.0, G_VCENTER))); - tvCRC_->SetShadow(true); - Visibility crcVisibility = Reporting::HasCRC(gamePath_) ? V_VISIBLE : V_GONE; - tvCRC_->SetVisibility(crcVisibility); - if (System_GetPropertyBool(SYSPROP_HAS_TEXT_CLIPBOARD)) { - tvCRCCopy_ = crcHoriz->Add(new Button(di->T("Copy to clipboard"), new LinearLayoutParams(0.0, G_VCENTER))); - tvCRCCopy_->OnClick.Add([this](UI::EventParams &) { - u32 crc = Reporting::RetrieveCRC(gamePath_); - char buffer[16]; - snprintf(buffer, sizeof(buffer), "%08X", crc); - System_CopyStringToClipboard(buffer); - // Success indication. Not worth a translatable string. - g_OSD.Show(OSDType::MESSAGE_SUCCESS, buffer, 1.0f); - return UI::EVENT_DONE; - }); - tvCRCCopy_->SetVisibility(crcVisibility); - tvCRCCopy_->SetScale(0.82f); - } else { - tvCRCCopy_ = nullptr; + + if (fileTypeSupportCRC) { + // CRC button makes sense. + tvCRC_ = crcHoriz->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(0.0, G_VCENTER))); + tvCRC_->SetShadow(true); + Visibility crcVisibility = Reporting::HasCRC(gamePath_) ? V_VISIBLE : V_GONE; + tvCRC_->SetVisibility(crcVisibility); + if (System_GetPropertyBool(SYSPROP_HAS_TEXT_CLIPBOARD)) { + tvCRCCopy_ = crcHoriz->Add(new Button(di->T("Copy to clipboard"), new LinearLayoutParams(0.0, G_VCENTER))); + tvCRCCopy_->OnClick.Add([this](UI::EventParams &) { + u32 crc = Reporting::RetrieveCRC(gamePath_); + char buffer[16]; + snprintf(buffer, sizeof(buffer), "%08X", crc); + System_CopyStringToClipboard(buffer); + // Success indication. Not worth a translatable string. + g_OSD.Show(OSDType::MESSAGE_SUCCESS, buffer, 1.0f); + return UI::EVENT_DONE; + }); + tvCRCCopy_->SetVisibility(crcVisibility); + tvCRCCopy_->SetScale(0.82f); + } else { + tvCRCCopy_ = nullptr; + } } tvVerified_ = infoLayout->Add(new NoticeView(NoticeLevel::INFO, ga->T("Click \"Calculate CRC\" to verify ISO"), "", new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); @@ -269,21 +290,6 @@ void GameScreen::CreateViews() { btnSetBackground_->OnClick.Handle(this, &GameScreen::OnSetBackground); btnSetBackground_->SetVisibility(V_GONE); - bool fileTypeSupportCRC = false; - if (info) { - switch (info->fileType) { - case IdentifiedFileType::PSP_PBP: - case IdentifiedFileType::PSP_PBP_DIRECTORY: - case IdentifiedFileType::PSP_ISO_NP: - case IdentifiedFileType::PSP_ISO: - fileTypeSupportCRC = true; - break; - - default: - break; - } - } - isHomebrew_ = info && info->region > GAMEREGION_MAX; if (fileTypeSupportCRC && !isHomebrew_ && !Reporting::HasCRC(gamePath_) ) { btnCalcCRC_ = rightColumnItems->Add(new ChoiceWithValueDisplay(&CRC32string, ga->T("Calculate CRC"), I18NCat::NONE)); From d9a19ed51f9055a7d86c165486c2420b1f690c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Oct 2024 15:38:50 +0200 Subject: [PATCH 3/7] Fix ShowFileInFolder --- Windows/W32Util/Misc.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Windows/W32Util/Misc.cpp b/Windows/W32Util/Misc.cpp index 0583c5963f..5aed03198a 100644 --- a/Windows/W32Util/Misc.cpp +++ b/Windows/W32Util/Misc.cpp @@ -10,6 +10,7 @@ #include "Common/Data/Encoding/Utf8.h" #include "Common/StringUtils.h" #include "Common/File/FileUtil.h" +#include "Common/Log.h" bool KeyDownAsync(int vkey) { #if PPSSPP_PLATFORM(UWP) @@ -101,14 +102,22 @@ namespace W32Util // SHParseDisplayName can't handle relative paths, so normalize first. std::string resolved = ReplaceAll(File::ResolvePath(path), "/", "\\"); - SFGAOF flags{}; + // Shell also can't handle \\?\UNC\ paths. + // TODO: Move this to ResolvePath? + if (startsWith(resolved, "\\\\?\\UNC\\")) { + resolved = "\\" + resolved.substr(7); + } + PIDLIST_ABSOLUTE pidl = nullptr; - HRESULT hr = SHParseDisplayName(ConvertUTF8ToWString(resolved).c_str(), nullptr, &pidl, 0, &flags); + std::wstring wresolved = ConvertUTF8ToWString(resolved); + HRESULT hr = SHParseDisplayName(wresolved.c_str(), nullptr, &pidl, 0, nullptr); if (pidl) { if (SUCCEEDED(hr)) SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0); - CoTaskMemFree(pidl); + ILFree(pidl); + } else { + ERROR_LOG(Log::System, "SHParseDisplayName failed: %s", resolved.c_str()); } } From 6797a24199e260c5c337f3133a9faa763898e788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Oct 2024 15:42:19 +0200 Subject: [PATCH 4/7] Texture saving: Try to limp along if memory allocation of buffer memory fails --- GPU/Common/TextureReplacer.cpp | 32 ++++++++++++++++++++----------- GPU/Vulkan/TextureCacheVulkan.cpp | 2 +- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/GPU/Common/TextureReplacer.cpp b/GPU/Common/TextureReplacer.cpp index 572f46d4c1..4274a5654a 100644 --- a/GPU/Common/TextureReplacer.cpp +++ b/GPU/Common/TextureReplacer.cpp @@ -664,18 +664,21 @@ static bool WriteTextureToPNG(png_imagep image, const Path &filename, int conver // can be pretty slow. class SaveTextureTask : public Task { public: - std::vector rgbaData; + // malloc'd + u8 *rgbaData = nullptr; int w = 0; int h = 0; - int pitch = 0; // bytes Path filename; Path saveFilename; u32 replacedInfoHash = 0; - SaveTextureTask(std::vector &&_rgbaData) : rgbaData(std::move(_rgbaData)) {} + SaveTextureTask(u8 *_rgbaData) : rgbaData(_rgbaData) {} + ~SaveTextureTask() { + free(rgbaData); + } // This must be set to I/O blocking because of Android storage (so we attach the thread to JNI), while being CPU heavy too. TaskType Type() const override { return TaskType::IO_BLOCKING; } @@ -711,7 +714,7 @@ public: png.format = PNG_FORMAT_RGBA; png.width = w; png.height = h; - bool success = WriteTextureToPNG(&png, saveFilename, 0, rgbaData.data(), pitch, nullptr); + bool success = WriteTextureToPNG(&png, saveFilename, 0, rgbaData, w * 4, nullptr); png_image_free(&png); if (png.warning_or_error >= 2) { ERROR_LOG(Log::G3D, "Saving texture to PNG produced errors."); @@ -735,9 +738,9 @@ bool TextureReplacer::WillSave(const ReplacedTextureDecodeInfo &replacedInfo) co return true; } -void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const ReplacedTextureDecodeInfo &replacedInfo, const void *data, int pitch, int level, int origW, int origH, int scaledW, int scaledH) { +void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const ReplacedTextureDecodeInfo &replacedInfo, const void *data, int srcPitch, int level, int origW, int origH, int scaledW, int scaledH) { _assert_msg_(saveEnabled_, "Texture saving not enabled"); - _assert_(pitch >= 0); + _assert_(srcPitch >= 0); if (!WillSave(replacedInfo)) { // Ignore. @@ -787,6 +790,10 @@ void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const Repla int w = scaledW; int h = scaledH; + if (w == 0 || h == 0) { + return; + } + // Only save the hashed portion of the PNG. int lookupW; int lookupH; @@ -795,15 +802,19 @@ void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const Repla h = lookupH * (scaledH / origH); } - std::vector saveBuf; + + size_t saveBufSize = w * h * 4; + u8 *saveBuf = (u8 *)malloc(saveBufSize); + if (!saveBuf) { + ERROR_LOG(Log::G3D, "Failed to allocated %d bytes of memory for saving a texture", (int)saveBufSize); + return; + } // Copy data to a buffer so we can send it to the thread. Might as well compact-away the pitch // while we're at it. - saveBuf.resize(w * h * 4); for (int y = 0; y < h; y++) { - memcpy((u8 *)saveBuf.data() + y * w * 4, (const u8 *)data + y * pitch, w * 4); + memcpy(saveBuf + y * w * 4, (const u8 *)data + y * srcPitch, w * 4); } - pitch = w * 4; SaveTextureTask *task = new SaveTextureTask(std::move(saveBuf)); @@ -812,7 +823,6 @@ void TextureReplacer::NotifyTextureDecoded(ReplacedTexture *texture, const Repla task->w = w; task->h = h; - task->pitch = pitch; task->replacedInfoHash = replacedInfo.hash; g_threadManager.EnqueueTask(task); // We don't care about waiting for the task. It'll be fine. diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index a38a18fc11..6eb7826bdc 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -496,7 +496,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { } if (plan.saveTexture) { - INFO_LOG(Log::G3D, "About to save texture"); + INFO_LOG(Log::G3D, "About to save texture (%dx%d)", plan.createW, plan.createH); actualFmt = VULKAN_8888_FORMAT; } From 9e564e36758d3bdb9a82d878339bf1470ac0e9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Oct 2024 15:42:48 +0200 Subject: [PATCH 5/7] Add a null check in zip file parsing --- Core/Util/GameManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index 7c2045236c..f5a93cc4ea 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -637,6 +637,11 @@ bool ZipExtractFileToMemory(struct zip *z, int fileIndex, std::string *data) { data->resize(readSize); zip_file *zf = zip_fopen_index(z, fileIndex, 0); + if (!zf) { + ERROR_LOG(Log::HLE, "Failed to zip_fopen_index file %d from zip", fileIndex); + return false; + } + zip_int64_t retval = zip_fread(zf, data->data(), readSize); zip_fclose(zf); From 1ac580b726ec865ef4ba62406c53f50e8bfa0f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Oct 2024 15:54:23 +0200 Subject: [PATCH 6/7] Buffer::Printf: Properly check for encoding failure --- Common/Buffer.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Common/Buffer.cpp b/Common/Buffer.cpp index 4cc3c3c08c..1df469d6ba 100644 --- a/Common/Buffer.cpp +++ b/Common/Buffer.cpp @@ -102,16 +102,17 @@ int Buffer::OffsetToAfterNextCRLF() { } void Buffer::Printf(const char *fmt, ...) { - char buffer[2048]; + char buffer[4096]; va_list vl; va_start(vl, fmt); - size_t retval = vsnprintf(buffer, sizeof(buffer), fmt, vl); - if ((int)retval >= (int)sizeof(buffer)) { + int retval = vsnprintf(buffer, sizeof(buffer), fmt, vl); + if (retval >= (int)sizeof(buffer)) { // Output was truncated. TODO: Do something. ERROR_LOG(Log::IO, "Buffer::Printf truncated output"); } - if ((int)retval < 0) { - ERROR_LOG(Log::IO, "Buffer::Printf failed"); + if (retval < 0) { + ERROR_LOG(Log::IO, "Buffer::Printf failed, bad args?"); + return; } va_end(vl); char *ptr = Append(retval); From f1cbf1ba96cafdc5a3902092fec0b2eff55e91be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Oct 2024 15:59:46 +0200 Subject: [PATCH 7/7] Android TextRenderer: Add try {} around loading the Roboto font. Also improve an unrelated assert. --- Common/GPU/Vulkan/VulkanMemory.cpp | 2 +- android/src/org/ppsspp/ppsspp/TextRenderer.java | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanMemory.cpp b/Common/GPU/Vulkan/VulkanMemory.cpp index 146b4eba15..b4f1837729 100644 --- a/Common/GPU/Vulkan/VulkanMemory.cpp +++ b/Common/GPU/Vulkan/VulkanMemory.cpp @@ -74,8 +74,8 @@ VulkanPushPool::Block VulkanPushPool::CreateBlock(size_t size) { _assert_(result == VK_SUCCESS); result = vmaMapMemory(vulkan_->Allocator(), block.allocation, (void **)(&block.writePtr)); - _assert_msg_(result == VK_SUCCESS, "VulkanPushPool: Failed to map memory (result = %s)", VulkanResultToString(result)); + _assert_msg_(result == VK_SUCCESS, "VulkanPushPool: Failed to map memory (result = %s, size = %d)", VulkanResultToString(result), (int)size); _assert_msg_(block.writePtr != nullptr, "VulkanPushPool: Failed to map memory on block of size %d", (int)block.size); return block; } diff --git a/android/src/org/ppsspp/ppsspp/TextRenderer.java b/android/src/org/ppsspp/ppsspp/TextRenderer.java index 6bc2102d09..a19f2982e6 100644 --- a/android/src/org/ppsspp/ppsspp/TextRenderer.java +++ b/android/src/org/ppsspp/ppsspp/TextRenderer.java @@ -22,12 +22,16 @@ public class TextRenderer { } public static void init(Context ctx) { - robotoCondensed = Typeface.createFromAsset(ctx.getAssets(), "Roboto-Condensed.ttf"); - if (robotoCondensed != null) { - Log.i(TAG, "Successfully loaded Roboto Condensed"); - textPaint.setTypeface(robotoCondensed); - } else { - Log.e(TAG, "Failed to load Roboto Condensed"); + try { + robotoCondensed = Typeface.createFromAsset(ctx.getAssets(), "Roboto-Condensed.ttf"); + if (robotoCondensed != null) { + Log.i(TAG, "Successfully loaded Roboto Condensed"); + textPaint.setTypeface(robotoCondensed); + } else { + Log.e(TAG, "Failed to load Roboto Condensed"); + } + } catch (Exception e) { + Log.e(TAG, "Exception when loading typeface. shouldn't happen but is reported. We just fall back." + e); } highContrastFontsEnabled = Settings.Secure.getInt(ctx.getContentResolver(), "high_text_contrast_enabled", 0) == 1; }