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,13 +276,17 @@ void GBResizeSram(struct GB* gb, size_t size) {
vf->seek(vf, size, SEEK_SET);
vf->write(vf, extdataBuffer, vfSize & 0xFF);
}
gb->memory.sram = vf->map(vf, size, MAP_WRITE);
memset(&gb->memory.sram[vfSize], 0xFF, size - vfSize);
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);
}
gb->memory.sram = vf->map(vf, size, MAP_WRITE);
if (size) {
gb->memory.sram = vf->map(vf, size, MAP_WRITE);
}
}
} else {
if (gb->memory.sram) {
@ -296,9 +300,11 @@ void GBResizeSram(struct GB* gb, size_t size) {
gb->sramVf = newVf;
vf->truncate(vf, size);
}
gb->memory.sram = vf->map(vf, size, MAP_READ);
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) {