git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit c6a968ed747950d7ed435c634bab265091b4a3fa
parent e69f6b85794e87730aded713919c535e634add45
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Tue, 22 Jul 2025 00:03:37 +0300

Make sure to display an alert if saving a state failed

Diffstat:
MiOS/GBViewController.m30+++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/iOS/GBViewController.m b/iOS/GBViewController.m @@ -847,15 +847,31 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) - (void)saveStateToFile:(NSString *)file { NSString *tempPath = [file stringByAppendingPathExtension:@"tmp"]; - if (!GB_save_state(&_gb, tempPath.UTF8String)) { + int error = GB_save_state(&_gb, tempPath.UTF8String); + if (!error) { rename(tempPath.UTF8String, file.UTF8String); + NSData *data = [NSData dataWithBytes:_gbView.previousBuffer + length:GB_get_screen_width(&_gb) * + GB_get_screen_height(&_gb) * + sizeof(*_gbView.previousBuffer)]; + UIImage *screenshot = [self imageFromData:data width:GB_get_screen_width(&_gb) height:GB_get_screen_height(&_gb)]; + [UIImagePNGRepresentation(screenshot) writeToFile:[file stringByAppendingPathExtension:@"png"] atomically:false]; + } + else { + dispatch_async(dispatch_get_main_queue(), ^{ + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Could not Save State" + message:[NSString stringWithFormat:@"An error occured while attempting to save: %s", strerror(error)] + preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:@"Close" + style:UIAlertActionStyleCancel + handler:nil]]; + UIViewController *top = self; + while (top.presentedViewController) { + top = top.presentedViewController; + } + [top presentViewController:alert animated:true completion:nil]; + }); } - NSData *data = [NSData dataWithBytes:_gbView.previousBuffer - length:GB_get_screen_width(&_gb) * - GB_get_screen_height(&_gb) * - sizeof(*_gbView.previousBuffer)]; - UIImage *screenshot = [self imageFromData:data width:GB_get_screen_width(&_gb) height:GB_get_screen_height(&_gb)]; - [UIImagePNGRepresentation(screenshot) writeToFile:[file stringByAppendingPathExtension:@"png"] atomically:false]; } - (bool)loadStateFromFile:(NSString *)file

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.