From 117da602ca1de742a61221790646da6241adf6b0 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 23 Nov 2024 13:54:50 +0200 Subject: [PATCH] Prevent the rewind buffer from being reset unexpectedly on iOS --- iOS/GBViewController.m | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/iOS/GBViewController.m b/iOS/GBViewController.m index 530589ad0..c760156ca 100644 --- a/iOS/GBViewController.m +++ b/iOS/GBViewController.m @@ -78,6 +78,9 @@ @implementation GBViewController UIButton *_printerButton; UIActivityIndicatorView *_printerSpinner; NSMutableData *_currentPrinterImageData; + + NSString *_lastSavedROM; + NSDate *_saveDate; } static void loadBootROM(GB_gameboy_t *gb, GB_boot_rom_t type) @@ -697,7 +700,17 @@ - (void)loadROM } } } - GB_rewind_reset(&_gb); + + NSDate *date = nil; + [[NSURL fileURLWithPath:[GBROMManager sharedManager].autosaveStateFile] getResourceValue:&date + forKey:NSURLContentModificationDateKey + error:nil]; + + // Reset the rewind buffer only if we switched ROMs or had the save state change externally + if (![_lastSavedROM isEqual:[GBROMManager sharedManager].currentROM] || + ![_saveDate isEqual:date]) { + GB_rewind_reset(&_gb); + } } } else { @@ -1155,6 +1168,14 @@ - (void)postRun if (!_swappingROM) { GB_save_battery(&_gb, [GBROMManager sharedManager].batterySaveFile.fileSystemRepresentation); [self saveStateToFile:[GBROMManager sharedManager].autosaveStateFile]; + + NSDate *date; + [[NSURL fileURLWithPath:[GBROMManager sharedManager].autosaveStateFile] getResourceValue:&date + forKey:NSURLContentModificationDateKey + error:nil]; + _saveDate = date; + _lastSavedROM = [GBROMManager sharedManager].currentROM; + } [[GBHapticManager sharedManager] setRumbleStrength:0]; if (@available(iOS 14.0, *)) {