diff --git a/CHANGES b/CHANGES index f93c546c5..036378226 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,7 @@ Emulation fixes: - GBA BIOS: Fix clobbering registers with word-sized CpuSet - GBA SIO: Fix normal mode SI/SO semantics (fixes mgba.io/i/2925) Other fixes: + - GBA Savedata: Fix crash when resizing flash save games for RTC data - mGUI: Fix cases where an older save state screenshot would be shown (fixes mgba.io/i/2183) - Qt: Re-enable sync for multiplayer windows that aren't connected (fixes mgba.io/i/2974) - Qt: Fix mute settings not being loaded on setting screen (fixes mgba.io/i/2990) diff --git a/src/gba/savedata.c b/src/gba/savedata.c index 08c3db8a4..339f0a1ac 100644 --- a/src/gba/savedata.c +++ b/src/gba/savedata.c @@ -602,14 +602,23 @@ void GBASavedataRTCWrite(struct GBASavedata* savedata) { size_t size = GBASavedataSize(savedata); savedata->vf->seek(savedata->vf, size & ~0xFF, SEEK_SET); + int bank = 0; if ((savedata->vf->size(savedata->vf) & 0xFF) != sizeof(buffer)) { // Writing past the end of the file can invalidate the file mapping + if (savedata->type == SAVEDATA_FLASH1M) { + bank = savedata->currentBank == &savedata->data[0x10000]; + } savedata->vf->unmap(savedata->vf, savedata->data, size); savedata->data = NULL; } savedata->vf->write(savedata->vf, &buffer, sizeof(buffer)); if (!savedata->data) { savedata->data = savedata->vf->map(savedata->vf, size, MAP_WRITE); + if (savedata->type == SAVEDATA_FLASH1M) { + savedata->currentBank = &savedata->data[bank << 16]; + } else if (savedata->type == SAVEDATA_FLASH512) { + savedata->currentBank = savedata->data; + } } }