Bug 3489 - Exception is raised when dismiss a modal view controller that earlier had a modal view controller itself. Seen after the update to 5.2.4
Summary: Exception is raised when dismiss a modal view controller that earlier had a m...
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2012-02-15 19:33 UTC by matteo
Modified: 2014-12-03 02:52 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description matteo 2012-02-15 19:33:23 UTC

Comment 1 Sebastien Pouliot 2012-02-15 21:49:14 UTC
please attach a test case that we can use to duplicate the issue
Comment 2 matteo 2012-02-16 04:07:21 UTC
MonoTouch.UIKit.UIViewController A = new MonoTouch.UIKit.UIViewController();
MonoTouch.UIKit.UIViewController B = new MonoTouch.UIKit.UIViewController();
MonoTouch.UIKit.UIViewController C = new MonoTouch.UIKit.UIViewController();
A.PresentModalViewController (B, true);
B.PresentModalViewController (C, true);
B.DismissModalViewControllerAnimated (true);
A.DismissModalViewControllerAnimated (true); //error
Comment 3 Sebastien Pouliot 2012-02-16 09:52:23 UTC
Comment 4 Aleksander Heintz 2012-02-16 14:48:36 UTC
I'm seeing the same error when simply doing

UIViewController Wrap(DialogViewController dvc)
    return new UINavigationController (dvc);

var A = new DialogViewController(root, false);
var B = new DialogViewController(root2, false);
var C = new DialogViewController(root3, false);

A.PresentModalViewController(Wrap(B), true);
B.PresentModalViewController(Wrap(C), true);

C.DismissModalViewControllerAnimated(true); // Error here
Comment 5 Sebastien Pouliot 2012-02-16 16:15:33 UTC
Matteo, I can reproduce this and I have a fix (note that the previous fix was removed from the upcoming MT 5.2.5).

Aleksander, I cannot reproduce your test case, i.e. it's not throwing an exception for me. It must be missing something else. Can you give me a more complete test case ?

Also you will likely run into other problems if you present `Wrap(C)` and do the dismiss on `C`. It will work, on the ObjectiveC side, however the managed side won't be able to track the references properly (and that will lead to memory leaks, when a reference won't be freed, or a crash when a reference was freed when it should not have been). Code like:

var A = new DialogViewController(root, false);
var B = Wrap (new DialogViewController(root2, false));
var C = Wrap (new DialogViewController(root3, false));

A.PresentModalViewController(B, true);
B.PresentModalViewController(C, true);

won't have the problem.
Comment 6 tkandiliotis 2012-02-20 17:44:14 UTC
I have this problem as well... This breaks my code
Comment 7 tkandiliotis 2012-02-20 17:46:05 UTC
Do you know when 5.2.5 is going to be released ?


Take care
Comment 8 Sebastien Pouliot 2012-02-20 18:27:40 UTC
MT 5.2.5 is already released. MonoDevelop should offer it to you (update) once restarted.
Comment 9 Aleksander Heintz 2012-02-20 22:35:05 UTC
My problem was introduced with this update though (5.2.4). However, I was able to fix it. I created my own stack that I gave my root-controller, and I just let that stack manage all my modals for me. So I now simply write ViewStack.ShowModal(Wrap(C)); and it makes sure to call the PresentModalViewController on the topmost modal viewcontroller (the wrapped B). ViewStack.DismissModal() also calls dismiss on the right controller, and cause it's a static Stack<UIViewController> a refference to the wrapper-controller is allways kept.
Comment 10 Sebastien Pouliot 2012-02-21 09:07:03 UTC
Aleksander, what you're doing is similar to the original fix (removed in 5.2.5) and I don't doubt you had an issue with it (in 5.2.4).

However your test case (in comment #4) worked on 5.2.4 (so it's likely a bit different from your original issue) and I want to be sure that the fix (once re-introduced, e.g. 5.2.6) won't break under other conditions (for you or others). Are you able to duplicate the original issue again ?
Comment 11 Sebastien Pouliot 2012-02-26 12:11:16 UTC
Fix committed to 5.2-series branch and will be in 5.2.6

I'd still like your original test case that failed to ensure this won't cause other regressions