diff --git a/CHANGES b/CHANGES index 7876950e6..8501f03a1 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,7 @@ Emulation fixes: Other fixes: - Core: Fix inconsistencies with setting game-specific overrides (fixes mgba.io/i/2963) - Debugger: Fix writing to specific segment in command-line debugger + - 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: Fix savestate preview sizes with different scales (fixes mgba.io/i/2560) - Qt: Re-enable sync for multiplayer windows that aren't connected (fixes mgba.io/i/2974) diff --git a/src/gba/savedata.c b/src/gba/savedata.c index 512af02c9..e7176650b 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; + } } }