From 31a7f53282040c7df93204d647de470390b96c4b Mon Sep 17 00:00:00 2001 From: Jesse Talavera Date: Wed, 13 Mar 2024 09:55:20 -0400 Subject: Fix a crash when using DSi mode in debug builds on macOS (#1976) Store the BIOS images in `NDSArgs`/`DSiArgs` through pointers, not directly - This will make it easier to keep such objects on the stack --- src/frontend/qt_sdl/EmuThread.cpp | 8 ++++---- src/frontend/qt_sdl/ROMManager.cpp | 40 +++++++++++++++++++------------------- src/frontend/qt_sdl/ROMManager.h | 12 +++++++----- 3 files changed, 31 insertions(+), 29 deletions(-) (limited to 'src/frontend/qt_sdl') diff --git a/src/frontend/qt_sdl/EmuThread.cpp b/src/frontend/qt_sdl/EmuThread.cpp index 0728a08..d16aead 100644 --- a/src/frontend/qt_sdl/EmuThread.cpp +++ b/src/frontend/qt_sdl/EmuThread.cpp @@ -131,8 +131,8 @@ std::unique_ptr EmuThread::CreateConsole( NDSArgs ndsargs { std::move(ndscart), std::move(gbacart), - *arm9bios, - *arm7bios, + std::move(arm9bios), + std::move(arm7bios), std::move(*firmware), #ifdef JIT_ENABLED Config::JIT_Enable ? std::make_optional(jitargs) : std::nullopt, @@ -165,8 +165,8 @@ std::unique_ptr EmuThread::CreateConsole( auto sdcard = ROMManager::LoadDSiSDCard(); DSiArgs args { std::move(ndsargs), - *arm9ibios, - *arm7ibios, + std::move(arm9ibios), + std::move(arm7ibios), std::move(*nand), std::move(sdcard), Config::DSiFullBIOSBoot, diff --git a/src/frontend/qt_sdl/ROMManager.cpp b/src/frontend/qt_sdl/ROMManager.cpp index de1d864..6550846 100644 --- a/src/frontend/qt_sdl/ROMManager.cpp +++ b/src/frontend/qt_sdl/ROMManager.cpp @@ -512,59 +512,59 @@ void LoadCheats(NDS& nds) nds.AREngine.SetCodeFile(CheatsOn ? CheatFile : nullptr); } -std::optional> LoadARM9BIOS() noexcept +std::unique_ptr LoadARM9BIOS() noexcept { if (!Config::ExternalBIOSEnable) { - return Config::ConsoleType == 0 ? std::make_optional(bios_arm9_bin) : std::nullopt; + return Config::ConsoleType == 0 ? std::make_unique(bios_arm9_bin) : nullptr; } if (FileHandle* f = OpenLocalFile(Config::BIOS9Path, Read)) { - std::array bios {}; + std::unique_ptr bios = std::make_unique(); FileRewind(f); - FileRead(bios.data(), sizeof(bios), 1, f); + FileRead(bios->data(), bios->size(), 1, f); CloseFile(f); Log(Info, "ARM9 BIOS loaded from %s\n", Config::BIOS9Path.c_str()); return bios; } Log(Warn, "ARM9 BIOS not found\n"); - return std::nullopt; + return nullptr; } -std::optional> LoadARM7BIOS() noexcept +std::unique_ptr LoadARM7BIOS() noexcept { if (!Config::ExternalBIOSEnable) { - return Config::ConsoleType == 0 ? std::make_optional(bios_arm7_bin) : std::nullopt; + return Config::ConsoleType == 0 ? std::make_unique(bios_arm7_bin) : nullptr; } if (FileHandle* f = OpenLocalFile(Config::BIOS7Path, Read)) { - std::array bios {}; - FileRead(bios.data(), sizeof(bios), 1, f); + std::unique_ptr bios = std::make_unique(); + FileRead(bios->data(), bios->size(), 1, f); CloseFile(f); Log(Info, "ARM7 BIOS loaded from %s\n", Config::BIOS7Path.c_str()); return bios; } Log(Warn, "ARM7 BIOS not found\n"); - return std::nullopt; + return nullptr; } -std::optional> LoadDSiARM9BIOS() noexcept +std::unique_ptr LoadDSiARM9BIOS() noexcept { if (FileHandle* f = OpenLocalFile(Config::DSiBIOS9Path, Read)) { - std::array bios {}; - FileRead(bios.data(), sizeof(bios), 1, f); + std::unique_ptr bios = std::make_unique(); + FileRead(bios->data(), bios->size(), 1, f); CloseFile(f); if (!Config::DSiFullBIOSBoot) { // herp - *(u32*)&bios[0] = 0xEAFFFFFE; // overwrites the reset vector + *(u32*)bios->data() = 0xEAFFFFFE; // overwrites the reset vector // TODO!!!! // hax the upper 32K out of the goddamn DSi @@ -575,21 +575,21 @@ std::optional> LoadDSiARM9BIOS() noexcept } Log(Warn, "ARM9i BIOS not found\n"); - return std::nullopt; + return nullptr; } -std::optional> LoadDSiARM7BIOS() noexcept +std::unique_ptr LoadDSiARM7BIOS() noexcept { if (FileHandle* f = OpenLocalFile(Config::DSiBIOS7Path, Read)) { - std::array bios {}; - FileRead(bios.data(), sizeof(bios), 1, f); + std::unique_ptr bios = std::make_unique(); + FileRead(bios->data(), bios->size(), 1, f); CloseFile(f); if (!Config::DSiFullBIOSBoot) { // herp - *(u32*)&bios[0] = 0xEAFFFFFE; // overwrites the reset vector + *(u32*)bios->data() = 0xEAFFFFFE; // overwrites the reset vector // TODO!!!! // hax the upper 32K out of the goddamn DSi @@ -600,7 +600,7 @@ std::optional> LoadDSiARM7BIOS() noexcept } Log(Warn, "ARM7i BIOS not found\n"); - return std::nullopt; + return nullptr; } Firmware GenerateFirmware(int type) noexcept diff --git a/src/frontend/qt_sdl/ROMManager.h b/src/frontend/qt_sdl/ROMManager.h index 38ed65c..6d0b81d 100644 --- a/src/frontend/qt_sdl/ROMManager.h +++ b/src/frontend/qt_sdl/ROMManager.h @@ -26,6 +26,8 @@ #include #include "MemConstants.h" + +#include #include #include #include @@ -56,11 +58,11 @@ void ClearBackupState(); /// Returns the configured ARM9 BIOS loaded from disk, /// the FreeBIOS if external BIOS is disabled and we're in NDS mode, -/// or nullopt if loading failed. -std::optional> LoadARM9BIOS() noexcept; -std::optional> LoadARM7BIOS() noexcept; -std::optional> LoadDSiARM9BIOS() noexcept; -std::optional> LoadDSiARM7BIOS() noexcept; +/// or nullptr if loading failed. +std::unique_ptr LoadARM9BIOS() noexcept; +std::unique_ptr LoadARM7BIOS() noexcept; +std::unique_ptr LoadDSiARM9BIOS() noexcept; +std::unique_ptr LoadDSiARM7BIOS() noexcept; std::optional GetDSiSDCardArgs() noexcept; std::optional LoadDSiSDCard() noexcept; std::optional GetDLDISDCardArgs() noexcept; -- cgit v1.2.3