mirror of https://github.com/mgba-emu/mgba.git
GBA Savedata: Fix crash when resizing flash save games for RTC data
This commit is contained in:
parent
050c5da263
commit
ce4024a29e
1
CHANGES
1
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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue