GB: Don't try to map a 0-byte SRAM (fixes #2668)

This commit is contained in:
Vicki Pfau 2022-09-27 05:32:13 -07:00
parent c06d38449d
commit 55c2efa3ea
2 changed files with 12 additions and 5 deletions

View File

@ -63,6 +63,7 @@ Other fixes:
- FFmpeg: Fix GIF recording (fixes mgba.io/i/2393)
- GB: Fix temporary saves
- GB: Fix replacing the ROM crashing when accessing ROM base
- GB: Don't try to map a 0-byte SRAM (fixes mgba.io/i/2668)
- GB, GBA: Save writeback-pending masked saves on unload (fixes mgba.io/i/2396)
- mGUI: Fix FPS counter after closing menu
- Qt: Fix some hangs when using the debugger console

View File

@ -276,14 +276,18 @@ void GBResizeSram(struct GB* gb, size_t size) {
vf->seek(vf, size, SEEK_SET);
vf->write(vf, extdataBuffer, vfSize & 0xFF);
}
if (size) {
gb->memory.sram = vf->map(vf, size, MAP_WRITE);
memset(&gb->memory.sram[vfSize], 0xFF, size - vfSize);
}
} else if (size > gb->sramSize || !gb->memory.sram) {
if (gb->memory.sram) {
vf->unmap(vf, gb->memory.sram, gb->sramSize);
}
if (size) {
gb->memory.sram = vf->map(vf, size, MAP_WRITE);
}
}
} else {
if (gb->memory.sram) {
vf->unmap(vf, gb->memory.sram, gb->sramSize);
@ -296,9 +300,11 @@ void GBResizeSram(struct GB* gb, size_t size) {
gb->sramVf = newVf;
vf->truncate(vf, size);
}
if (size) {
gb->memory.sram = vf->map(vf, size, MAP_READ);
}
if (gb->memory.sram == (void*) -1) {
}
if (!size || gb->memory.sram == (void*) -1) {
gb->memory.sram = NULL;
}
} else if (size) {