diff --git a/Limelight/ViewControllers/LoadingFrameViewController.m b/Limelight/ViewControllers/LoadingFrameViewController.m index 8f95b18..550ea60 100644 --- a/Limelight/ViewControllers/LoadingFrameViewController.m +++ b/Limelight/ViewControllers/LoadingFrameViewController.m @@ -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();