From 9ae85bdccc95c13350877f4c073938166acf9c17 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 19 Nov 2020 20:12:19 -0800 Subject: [PATCH] mGUI: Don't attempt to preload files larger than can fit in RAM --- CHANGES | 1 + src/core/core.c | 2 +- src/feature/gui/gui-runner.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 90262a486..5bad8b01b 100644 --- a/CHANGES +++ b/CHANGES @@ -53,6 +53,7 @@ Other fixes: - Debugger: Close trace log when done tracing - FFmpeg: Fix some small memory leaks - FFmpeg: Fix encoding of time base + - mGUI: Don't attempt to preload files larger than can fit in RAM - Qt: Force OpenGL paint engine creation thread (fixes mgba.io/i/1642) - Qt: Fix static compilation in MinGW (fixes mgba.io/i/1769) - Qt: Fix a race condition in the frame inspector diff --git a/src/core/core.c b/src/core/core.c index 3b82e76cb..4df6636a0 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -146,7 +146,7 @@ bool mCorePreloadVFCB(struct mCore* core, struct VFile* vf, void (cb)(size_t, si extern uint32_t* romBuffer; extern size_t romBufferSize; if (size > romBufferSize) { - size = romBufferSize; + return false; } vfm = VFileFromMemory(romBuffer, size); #else diff --git a/src/feature/gui/gui-runner.c b/src/feature/gui/gui-runner.c index 75e2961c8..fe3999ad6 100644 --- a/src/feature/gui/gui-runner.c +++ b/src/feature/gui/gui-runner.c @@ -387,8 +387,19 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) { mCoreInitConfig(runner->core, runner->port); mInputMapInit(&runner->core->inputMap, &GBAInputInfo); - found = mCorePreloadFileCB(runner->core, path, _updateLoading, runner); + struct VFile* rom = mDirectorySetOpenPath(&runner->core->dirs, path, runner->core->isROM); + found = mCorePreloadVFCB(runner->core, rom, _updateLoading, runner); + +#ifdef FIXED_ROM_BUFFER + extern size_t romBufferSize; + if (!found && rom && (size_t) rom->size(rom) > romBufferSize) { + found = runner->core->loadROM(runner->core, rom); + } +#endif if (!found) { + if (rom) { + rom->close(rom); + } mLOG(GUI_RUNNER, WARN, "Failed to load %s!", path); mCoreConfigDeinit(&runner->core->config); runner->core->deinit(runner->core);