GB Core: Fix cloning savedata when backing file is outdated (fixes #3388)

This commit is contained in:
Vicki Pfau 2024-12-31 01:45:03 -08:00
parent 6b5638efda
commit abb9bec571
2 changed files with 25 additions and 11 deletions

View File

@ -19,6 +19,7 @@ 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
- FFmpeg: Fix failing to record videos with CRF video (fixes mgba.io/i/3368)
- GB Core: Fix cloning savedata when backing file is outdated (fixes mgba.io/i/3388)
- GB Serialize: Prevent loading invalid states where LY >= 144 in modes other than 1
- GBA: Fix getting game info for multiboot ROMs
- GBA Core: Fix booting into BIOS when skip BIOS is enabled

View File

@ -1167,19 +1167,32 @@ static struct mCheatDevice* _GBCoreCheatDevice(struct mCore* core) {
static size_t _GBCoreSavedataClone(struct mCore* core, void** sram) {
struct GB* gb = core->board;
struct VFile* vf = gb->sramVf;
if (vf) {
*sram = malloc(vf->size(vf));
vf->seek(vf, 0, SEEK_SET);
return vf->read(vf, *sram, vf->size(vf));
size_t sramSize = gb->sramSize;
size_t vfSize = 0;
size_t size = sramSize;
uint8_t* view = NULL;
if (gb->sramVf) {
vfSize = gb->sramVf->size(gb->sramVf);
if (vfSize > size) {
size = vfSize;
}
}
if (gb->sramSize) {
*sram = malloc(gb->sramSize);
memcpy(*sram, gb->memory.sram, gb->sramSize);
return gb->sramSize;
if (!size) {
*sram = NULL;
return 0;
}
*sram = NULL;
return 0;
view = malloc(size);
if (sramSize) {
memcpy(view, gb->memory.sram, gb->sramSize);
}
if (vfSize > sramSize) {
gb->sramVf->seek(gb->sramVf, sramSize, SEEK_SET);
gb->sramVf->read(gb->sramVf, &view[sramSize], vfSize - sramSize);
}
*sram = view;
return size;
}
static bool _GBCoreSavedataRestore(struct mCore* core, const void* sram, size_t size, bool writeback) {