diff --git a/CHANGES b/CHANGES index 5b351afae..028cdfd46 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,7 @@ Other fixes: - GBA: Fix maximum tile ID in caching for 256-color modes - GBA Video: Fix cache updating with proxy and GL renderers - Libretro: Fix crash when using Game Boy codes (fixes mgba.io/i/2281) + - mGUI: Fix crash if autosave file can't be opened (fixes mgba.io/i/2268) - Qt: Remove potentially deadlocking optimization - Qt: Fix corrupted savestate and fatal error text - Qt: Fix sprite compositing when sprite tiles go out of bounds (fixes mgba.io/i/2348) diff --git a/src/feature/gui/gui-runner.c b/src/feature/gui/gui-runner.c index d3945ba8b..9eab72ad1 100644 --- a/src/feature/gui/gui-runner.c +++ b/src/feature/gui/gui-runner.c @@ -181,10 +181,10 @@ static void _tryAutosave(struct mGUIRunner* runner) { #ifdef DISABLE_THREADING mCoreSaveState(runner->core, 0, SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_METADATA); #else + MutexLock(&runner->autosave.mutex); if (!runner->autosave.buffer) { runner->autosave.buffer = VFileMemChunk(NULL, 0); } - MutexLock(&runner->autosave.mutex); runner->autosave.core = runner->core; mCoreSaveStateNamed(runner->core, runner->autosave.buffer, SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_METADATA); ConditionWake(&runner->autosave.cond); @@ -739,7 +739,13 @@ THREAD_ENTRY mGUIAutosaveThread(void* context) { while (autosave->running) { ConditionWait(&autosave->cond, &autosave->mutex); if (autosave->running && autosave->core) { + if (!autosave->buffer) { + continue; + } struct VFile* vf = mCoreGetState(autosave->core, 0, true); + if (!vf) { + continue; + } void* mem = autosave->buffer->map(autosave->buffer, autosave->buffer->size(autosave->buffer), MAP_READ); vf->write(vf, mem, autosave->buffer->size(autosave->buffer)); autosave->buffer->unmap(autosave->buffer, mem, autosave->buffer->size(autosave->buffer));