Bug 3960 - DismissModalViewControllerAnimated() crashes on 5.2.9
Summary: DismissModalViewControllerAnimated() crashes on 5.2.9
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime (show other bugs)
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-03-18 16:12 UTC by René Ruppert
Modified: 2012-03-20 18:36 UTC (History)
4 users (show)

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


Attachments
Test Case (834 bytes, text/plain)
2012-03-18 19:42 UTC, Dennis Hills
Details
updated monotouch.dll for testing (3.03 MB, application/octet-stream)
2012-03-18 19:58 UTC, Sebastien Pouliot
Details

Description René Ruppert 2012-03-18 16:12:46 UTC
I have just upgraded to MT 5.2.9 from 5.2.6 and all DismissModalViewControllerAnimated() calls lead to this exception:

$exception
{System.NullReferenceException: Object reference not set to an instance of an object
  at MonoTouch.UIKit.UIView+<Animate>c__AnonStorey11.<>m__13 (Boolean x) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIView.cs:98 
  at MonoTouch.UIKit.UIView.TrampolineUICompletionHandler (IntPtr block, Boolean finished) [0x0004d] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIView.g.cs:1590 
  at (wrapper native-to-managed) MonoTouch.UIKit.UIView:TrampolineUICompletionHandler (intptr,int)
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at BrainloopMobile.Application.Main (System.String[] args) [0x00000] in /Users/rene/Documents/Develop/Projects/BrainloopMobile/210/BrainloopMobile/BrainloopMobile/Main.cs:15 }

I also tried to use the new DismissViewController() instead: same result.
It seems to crash after the UI loop updates the next time.
Comment 1 Dennis Hills 2012-03-18 18:49:20 UTC
+1 Having the same issue but can't reference bug #3950.

I was just looking through the Xamarin API and came across this:
It looks like MonoTouch.Foundation.NSAction has been replaced with UICompletionHandler for UIVIew animation. Scroll to the bottom. From the Forum, I believe that Sebastien is hinting at this implementation. I'm not sure what the best approach is in my case.
http://docs.xamarin.com/ios/releases/API_Changes/From_5.2.5_to_5.2.6

My code below is having a problem with the completion parameter below. This parameter may be NULL as referenced in the Apple docs. I wonder if René's problem is DismissViewController(bool, Action) should be DismissViewController(bool, UICompletionHandler handler)? I'm confused. So I'll wait to hear back from Xamarin before making any code changes to work around this bug.

//Allows a UINavigationController to push using a custom animation transition
public static void PushControllerWithTransition(this UINavigationController 
  target, UIViewController controllerToPush, 
  UIViewAnimationOptions transition)
{
  UIView.Transition(target.View, 0.75d, transition, delegate() {
    target.PushViewController(controllerToPush, false);
  }, null);
}
Comment 2 Sebastien Pouliot 2012-03-18 18:52:05 UTC
The above stack trace comes from a different thread (where the completion occurs). I cannot be 100% sure the fix for #3950 also cover this. 

I'll have a look but to be safe can you attach a sample test case so we do not issue a new version without a complete fix ? 
Thanks.
Comment 3 Sebastien Pouliot 2012-03-18 19:03:05 UTC
Dennis, your link to 5.2.6 changes shows it introduced a source incompatibility (by using UICompletionHandler).

5.2.9 provides support for both NSAction and UICompletionHandler (using [Animate|Transition]Notify) but that change introduced the NRE regression when `null` was used the `completion` parameter.

You should be able to work around this, for the code in comment #1, by changing your `null` argument to `delegate {}` (being non-null it will be called without causing an exception).

note: in the future please open a separate bug report if you do have the exact same error using the same API (otherwise bugs often gets closed with only a partial fix or a fix for a different issue). thanks :)
Comment 4 René Ruppert 2012-03-18 19:25:53 UTC
Sebastien, I'm willing to try if your change also fixes my issue here if you provide a DLL. Or is your fix in MT 5.3.0? Then I'll grab that from Alpha channel.

If you were referring to me wrt sample code: I cannot give you one. I tried to set something up but it doesn't fail. It seems to require one additional ingredient that is breaking it but I cannot figure out what it is. All I can say: I'm back to 5.2.5 now and there it is working, just as it did in 5.2.6.
Comment 5 Sebastien Pouliot 2012-03-18 19:32:05 UTC
René, thanks for trying isolating a test case :)

My fixes should be in 5.2.10+ and 5.3.1+ (i.e. it's not in anything being released right now). I'll review the code asap and then attach an updated monotouch.dll binary you can try on top of 5.2.5 (either with my current patch or a more complete one if I find anything else).
Comment 6 Dennis Hills 2012-03-18 19:42:53 UTC
Created attachment 1531 [details]
Test Case
Comment 7 Dennis Hills 2012-03-18 19:46:37 UTC
Sorry, maybe I should have created a new bug instead of trying to attached to René's. Anyway, as requested, I pasted my test case for the issue I'm having on 5.2.9. 

Sebastien, your suggested workaround (replacing null with an empty delegate in Comment #3 has been implemented and is working fine. Thanks.
Comment 8 Sebastien Pouliot 2012-03-18 19:58:45 UTC
Created attachment 1532 [details]
updated monotouch.dll for testing

To use the attached assembly (on top of MonoTouch 5.2.5) do:

1) backup your /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll and /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb files

2) copy the attached file to /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll

3) remove the /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb symbols (they won't match anymore)

4) clean, rebuild and test your application
Comment 9 Sebastien Pouliot 2012-03-18 20:00:57 UTC
Dennis, if the workaround works then it's what I already fixed in bug #3950 (but thanks anyway :-)
Comment 10 Sebastien Pouliot 2012-03-18 20:06:07 UTC
René, DismissModalViewControllerAnimated is a direct binding (generated code) that does not (directly) use the affected code. What likely happens is that the the objective-c selector `dismissModalViewControllerAnimated:` calls of the `animate*` selector on the dismissed view (and that code was buggy). 

If the assembly I attached works properly then it will confirm my suspicion that this is the same issue as #3950 (and just a surprising way to hit it).
Comment 11 Sebastien Pouliot 2012-03-19 13:47:09 UTC
I found out that the CoreAnimation sample (in github) exhibited the same error so I can confirm that this is fixed (by my earlier fix) and will be part of the next stable release.

Please let us know in the (unlikely) event that the attachment does not work for you.
Comment 12 René Ruppert 2012-03-19 15:16:33 UTC
I downloaded the DLL and replaced the only other copy of Monotouch.dll I found on my Mac (/Developer/MonoTouch/usr/share/doc/Monotouch).  Is that correct? If yes, then it is working.

The version reported is still 5.2.5
Comment 13 Sebastien Pouliot 2012-03-19 15:19:35 UTC
No, it's not. If you installed MonoTouch under /Developer (default) then your monotouch.dll with be under:
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll

it's version number will be either 5.2.9 or 5.2.10 (I don't recall when the version number was updated)
Comment 14 René Ruppert 2012-03-20 18:36:25 UTC
I have just updated view Monodevelop and it is working now in 5.2.10. Thanks for the quick fix.

Note You need to log in before you can comment on or make changes to this bug.