Skip to content

Commit

Permalink
Fixed a bug that resulted in crashes if the ROM list changed while th…
Browse files Browse the repository at this point in the history
…e library was open.
  • Loading branch information
LIJI32 committed Nov 21, 2024
1 parent 8f9e1e9 commit ebfc877
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions iOS/GBROMViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@implementation GBROMViewController
{
NSIndexPath *_renamingPath;
NSArray *_roms;
}

- (instancetype)init
Expand All @@ -20,6 +21,11 @@ - (instancetype)init
name:UIApplicationDidBecomeActiveNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self.tableView
selector:@selector(reloadData)
name:UIApplicationDidBecomeActiveNotification
object:nil];

return self;
}

Expand All @@ -31,7 +37,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 1) return 2;
return [GBROMManager sharedManager].allROMs.count;
return (_roms = [GBROMManager sharedManager].allROMs).count;
}

- (UITableViewCell *)cellForROM:(NSString *)rom
Expand Down Expand Up @@ -72,7 +78,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}
return cell;
}
return [self cellForROM:[GBROMManager sharedManager].allROMs[[indexPath indexAtPosition:1]]];
return [self cellForROM:_roms[[indexPath indexAtPosition:1]]];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Expand All @@ -96,7 +102,7 @@ - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInte

- (void)romSelectedAtIndex:(unsigned)index
{
NSString *rom = [GBROMManager sharedManager].allROMs[index];
NSString *rom = _roms[index];
[GBROMManager sharedManager].currentROM = rom;
[self.presentingViewController dismissViewControllerAnimated:true completion:nil];
}
Expand Down Expand Up @@ -178,7 +184,7 @@ - (UIModalPresentationStyle)modalPresentationStyle

- (void)deleteROMAtIndex:(unsigned)index
{
NSString *rom = [GBROMManager sharedManager].allROMs[index];
NSString *rom = _roms[index];

[[GBROMManager sharedManager] deleteROM:rom];
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
Expand Down Expand Up @@ -265,7 +271,7 @@ - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)

- (void)duplicateROMAtIndex:(unsigned)index
{
[[GBROMManager sharedManager] duplicateROM:[GBROMManager sharedManager].allROMs[index]];
[[GBROMManager sharedManager] duplicateROM:_roms[index]];
[self.tableView reloadData];
}

Expand Down

0 comments on commit ebfc877

Please sign in to comment.