Skip to content

Commit 1b14c97

Browse files
Merge pull request #1436 from wutschel/fix_serverlist_crash
Bugfix: Fix potential crash when deleting active server from list
2 parents 7bfccdb + 9ecf80f commit 1b14c97

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

XBMC Remote/HostManagementViewController.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ - (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEdi
251251
if (editingStyle == UITableViewCellEditingStyleDelete) {
252252
[AppDelegate.instance.arrayServerList removeObjectAtIndex:indexPath.row];
253253
[AppDelegate.instance saveServerList];
254+
if (indexPath.row < [tableView numberOfRowsInSection:indexPath.section]) {
255+
[tableView performBatchUpdates:^{
256+
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
257+
} completion:nil];
258+
}
259+
260+
// Be aware! Sending "XBMCServerHasChanged" results in calling reloadData. Therefore ensure this is not called
261+
// between updating arrayServerList and changing tableView to avoid a crash due to inconsistent amount of rows.
254262
NSIndexPath *selectedPath = storeServerSelection;
255263
if (selectedPath) {
256264
if (indexPath.row < selectedPath.row) {
@@ -266,11 +274,6 @@ - (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEdi
266274
[[NSNotificationCenter defaultCenter] postNotificationName:@"XBMCServerHasChanged" object:nil];
267275
}
268276
}
269-
if (indexPath.row < [tableView numberOfRowsInSection:indexPath.section]) {
270-
[tableView performBatchUpdates:^{
271-
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
272-
} completion:nil];
273-
}
274277
// Are there still editable entries?
275278
editTableButton.selected = editTableButton.enabled = AppDelegate.instance.arrayServerList.count > 0;
276279
}

0 commit comments

Comments
 (0)