Fix crash presenting the loading frame while old one is still dismissing

This commit is contained in:
Cameron Gutman 2018-12-28 20:51:29 -08:00
parent d18c713684
commit 5028eaed59

View File

@ -30,18 +30,46 @@
- (void)showLoadingFrame:(void (^)(void))completion {
if (!presented) {
Log(LOG_I, @"Loading frame presenting start");
presented = YES;
[[self activeViewController] presentViewController:self animated:NO completion:completion];
[[self activeViewController] presentViewController:self animated:NO completion:^{
Log(LOG_I, @"Loading frame presenting complete");
if (completion) {
completion();
}
}];
}
else if (completion) {
Log(LOG_E, @"Loading frame already shown!");
completion();
}
}
- (void)dismissLoadingFrame:(void (^)(void))completion {
if (presented) {
presented = NO;
[self dismissViewControllerAnimated:NO completion:completion];
Log(LOG_I, @"Loading frame hiding start");
[self dismissViewControllerAnimated:NO completion:^{
Log(LOG_I, @"Loading frame hiding complete");
// Since presented is set to NO here rather than
// immediately in dismissLoadingFrame, we may
// falsely avoid displaying the loading frame if
// a dismiss is in progress while attempting to show
// the frame. That's preferable to crashing due to
// displaying the same VC twice though.
//
// This scenario can happen if the app is suspended
// while the dismiss is in progress then on resume
// it attempts to display it again before the dismiss
// completes. It can be reproduced by rapidly pressing
// Home and switching back to Moonlight while in the app grid.
// It reproduces more easily if the VC transitions are animated.
self->presented = NO;
if (completion) {
completion();
}
}];
}
else if (completion) {
completion();