mGUI: Fix crash if autosave file can't be opened (fixes #2268)

This commit is contained in:
Vicki Pfau 2021-11-29 14:03:21 -08:00
parent 283196ceb3
commit c9e1b78426
2 changed files with 8 additions and 1 deletions

View File

@ -31,6 +31,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: Fix corrupted savestate and fatal error text
- Qt: Fix sprite compositing when sprite tiles go out of bounds (fixes mgba.io/i/2348)
Misc:

View File

@ -186,10 +186,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);
@ -775,7 +775,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));