diff --git a/src/gb/gb.c b/src/gb/gb.c index d09bdf83f..154aa2dfe 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -232,14 +232,15 @@ void GBSavedataUnmask(struct GB* gb) { void GBUnloadROM(struct GB* gb) { // TODO: Share with GBAUnloadROM - if (gb->memory.rom && gb->memory.romBase != gb->memory.rom) { - free(gb->memory.romBase); - } if (gb->memory.rom && gb->pristineRom != gb->memory.rom) { if (gb->yankedRomSize) { gb->yankedRomSize = 0; } mappedMemoryFree(gb->memory.rom, GB_SIZE_CART_MAX); + gb->memory.rom = gb->pristineRom; + } + if (gb->memory.rom && gb->memory.romBase != gb->memory.rom) { + free(gb->memory.romBase); } gb->memory.rom = 0; @@ -248,9 +249,9 @@ void GBUnloadROM(struct GB* gb) { gb->romVf->unmap(gb->romVf, gb->pristineRom, gb->pristineRomSize); #endif gb->romVf->close(gb->romVf); - gb->pristineRom = 0; gb->romVf = 0; } + gb->pristineRom = 0; struct VFile* vf = gb->sramVf; GBSramDeinit(gb); diff --git a/src/gba/gba.c b/src/gba/gba.c index 548d4e6b8..a39ba72cd 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -127,9 +127,9 @@ void GBAUnloadROM(struct GBA* gba) { gba->romVf->unmap(gba->romVf, gba->pristineRom, gba->pristineRomSize); #endif gba->romVf->close(gba->romVf); - gba->pristineRom = 0; gba->romVf = 0; } + gba->pristineRom = 0; GBASavedataDeinit(&gba->memory.savedata); if (gba->memory.savedata.realVf) {