Bug 29779 - Crash with UIPopoverControllerDelegate.WillReposition method
Summary: Crash with UIPopoverControllerDelegate.WillReposition method
Status: RESOLVED DUPLICATE of bug 29720
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-05-05 21:48 UTC by Miguel de Icaza [MSFT]
Modified: 2015-05-06 04:49 UTC (History)
3 users (show)

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


Attachments
Application that reproduces the issue, just run on simulator (6.41 KB, application/octet-stream)
2015-05-05 21:49 UTC, Miguel de Icaza [MSFT]
Details


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:
Status:
RESOLVED DUPLICATE of bug 29720

Description Miguel de Icaza [MSFT] 2015-05-05 21:48:24 UTC
I was trying to create a repro test case for #29768 and I got to the point while I tried to, I noticed that I am getting garbage out of the data that arrives to the WillReposition method for the "rect" reference parameter, followed by a mysterious crash when trying to access the "view"

The crash looks like this on simulator/iPad:

222 ######## this=<padApp2_d: 0x79d5f540>
333 ######## rect={X=-1.981599,Y=-1.981601,Width=3.845456E-39,Height=0}
Unhandled managed exception:
Object reference not set to an instance of an object (System.NullReferenceException)
  at System.String.FormatHelper (System.Text.StringBuilder result, IFormatProvider provider, System.String format, System.Object[] args) [0x00175] in /Users/builder/data/lanes/1503/6481535e/source/mono/mcs/class/corlib/System/String.cs:2023 
  at System.String.Format (IFormatProvider provider, System.String format, System.Object[] args) [0x00000] in /Users/builder/data/lanes/1503/6481535e/source/mono/mcs/class/corlib/System/String.cs:1951 
  at System.IO.TextWriter.WriteLine (System.String format, System.Object arg0) [0x00000] in /Users/builder/data/lanes/1503/6481535e/source/mono/external/referencesource/mscorlib/system/io/textwriter.cs:526 
  at System.IO.TextWriter+SyncTextWriter.WriteLine (System.String format, System.Object arg0) [0x00000] in /Users/builder/data/lanes/1503/6481535e/source/mono/external/referencesource/mscorlib/system/io/textwriter.cs:864 
  at (wrapper synchronized) System.IO.TextWriter/SyncTextWriter:WriteLine (string,object)
  at System.Console.WriteLine (System.String format, System.Object arg0) [0x00000] in /Users/builder/data/lanes/1503/6481535e/source/mono/mcs/class/corlib/System/Console.cs:469 
  at padApp2.d.WillReposition (UIKit.UIPopoverController popoverController, CoreGraphics.CGRect& rect, UIKit.UIView& view) [0x00049] in /miguel/Projects/padApp2/padApp2/AppDelegate.cs:17 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/1503/6481535e/source/maccore/src/UIKit/UIApplication.cs:63 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/1503/6481535e/source/maccore/src/UIKit/UIApplication.cs:47 
  at padApp2.Application.Main (System.String[] args) [0x00008] in /miguel/Projects/padApp2/padApp2/Main.cs:12 
Stacktrace:




	0   padApp2                             0x001099b7 mono_handle_native_sigsegv + 311
	1   padApp2                             0x00110701 sigabrt_signal_handler + 129
	2   libsystem_platform.dylib            0x07bf003b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   libsystem_sim_c.dylib               0x07987a5a abort + 156
	5   padApp2                             0x00295186 xamarin_unhandled_exception_handler + 342
	6   padApp2                             0x0010a22b mono_invoke_unhandled_exception_hook + 91
	7   padApp2                             0x001090b8 mono_handle_exception_internal + 6200
	8   padApp2                             0x00107879 mono_handle_exception + 41
	9   padApp2                             0x0009f930 altstack_handle_and_restore + 80
	10  ???                                 0x1479bff1 0x0 + 343523313
	11  ???                                 0x16e2835c 0x0 + 383943516
	12  ???                                 0x16e282e4 0x0 + 383943396
	13  ???                                 0x16e28246 0x0 + 383943238
	14  ???                                 0x16e281a8 0x0 + 383943080
	15  ???                                 0x16e2812f 0x0 + 383942959
	16  ???                                 0x16e22a5c 0x0 + 383920732
	17  ???                                 0x16e22c77 0x0 + 383921271
	18  padApp2                             0x001390e5 mono_jit_runtime_invoke + 725
	19  padApp2                             0x001d899f mono_runtime_invoke + 127
	20  padApp2                             0x0029f4b3 xamarin_trampoline + 5427
	21  UIKit                               0x0376b3f1 -[UIPopoverController popoverPresentationController:willRepositionPopoverToRect:inView:] + 96
	22  UIKit                               0x038cc30e __86-[UIPopoverPresentationController viewWillTransitionToSize:withTransitionCoordinator:]_block_invoke + 324
	23  UIKit                               0x0391108b -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] + 198
	24  UIKit                               0x0390d740 -[_UIViewControllerTransitionContext _runAlongsideCompletions] + 122
	25  UIKit                               0x0390d45c -[_UIViewControllerTransitionContext completeTransition:] + 142
	26  UIKit                               0x035cb8c7 __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke199 + 75
	27  UIKit                               0x0312d9be -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 318
	28  UIKit                               0x031111b2 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 206
	29  UIKit                               0x03111522 -[UIViewAnimationState animationDidStop:finished:] + 80
	30  QuartzCore                          0x09887571 _ZN2CA5Layer23run_animation_callbacksEPv + 307
	31  libdispatch.dylib                   0x078bdecf _dispatch_client_callout + 14
	32  libdispatch.dylib                   0x078a6ee3 _dispatch_main_queue_callback_4CF + 677
	33  CoreFoundation                      0x0068d8ee __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
	34  CoreFoundation                      0x0064b5f0 __CFRunLoopRun + 2256
	35  CoreFoundation                      0x0064aa5b CFRunLoopRunSpecific + 443
	36  CoreFoundation                      0x0064a88b CFRunLoopRunInMode + 123
	37  GraphicsServices                    0x09a712c9 GSEventRunModal + 192
	38  GraphicsServices                    0x09a71106 GSEventRun + 104
	39  UIKit                               0x030a3106 UIApplicationMain + 1526
	40  ???                                 0x147bfd48 0x0 + 343670088
	41  ???                                 0x147bfb40 0x0 + 343669568
	42  ???                                 0x147bdcc8 0x0 + 343661768
	43  ???                                 0x147bda04 0x0 + 343661060
	44  ???                                 0x147bdb90 0x0 + 343661456
	45  padApp2                             0x001390e5 mono_jit_runtime_invoke + 725
	46  padApp2                             0x001d899f mono_runtime_invoke + 127
	47  padApp2                             0x001ddab1 mono_runtime_exec_main + 401
	48  padApp2                             0x001dd861 mono_runtime_run_main + 721
	49  padApp2                             0x0009633d mono_jit_exec + 93
	50  padApp2                             0x002916d3 xamarin_main + 2531
	51  padApp2                             0x002a8dc2 main + 114
	52  libdyld.dylib                       0x078e3ac9 start + 1

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
Comment 1 Miguel de Icaza [MSFT] 2015-05-05 21:49:04 UTC
Created attachment 11079 [details]
Application that reproduces the issue, just run on simulator

This app reproduces the crash
Comment 2 Miguel de Icaza [MSFT] 2015-05-05 21:58:33 UTC
I can avoid the crash if I change the UIPopoverDelegate implementation to not override the method, and instead use a manual export, like this:

[Export ("popoverController:willRepositionPopoverToRect:inView:")]
		public unsafe void Rep (UIPopoverController popoverController, IntPtr rect, IntPtr view)
		{
			CGRect *p = (CGRect *) rect;


			Console.WriteLine("222 ######## this={0}",this);
			Console.WriteLine("333 ######## rect={0}",*p);
			Console.WriteLine ("444 ######## view={0}", ObjCRuntime.Runtime.GetNSObject (Marshal.ReadIntPtr (view)));
		}

Which indicates that our marshaling code is likely wrong for the "ref CGRect" or "ref UIView", which also explains the incorrect values rendered for the rectable.

With this change, instead of getting the non-sensical values for CGRect, I get what I expect:

Starting iPad 2
Launching application
Application launched. PID = 71321
Press enter to terminate the application
>Loaded assembly: /miguel/Library/Developer/CoreSimulator/Devices/CC22C5F5-9503-4491-8867-32F334980850/data/Containers/Bundle/Application/0FA518F2-AA76-4969-942E-65ABBEE853F9/padApp2.app/Xamarin.iOS.dll [External]
Loaded assembly: /miguel/Library/Developer/CoreSimulator/Devices/CC22C5F5-9503-4491-8867-32F334980850/data/Containers/Bundle/Application/0FA518F2-AA76-4969-942E-65ABBEE853F9/padApp2.app/System.dll [External]
Loaded assembly: /miguel/Library/Developer/CoreSimulator/Devices/CC22C5F5-9503-4491-8867-32F334980850/data/Containers/Bundle/Application/0FA518F2-AA76-4969-942E-65ABBEE853F9/padApp2.app/padApp2.exe
2015-05-05 21:55:42.038 padApp2[71321:10127951] 222 ######## this=<padApp2_d: 0x79730cc0>
2015-05-05 21:55:42.040 padApp2[71321:10127951] 333 ######## rect={X=0,Y=0,Width=1,Height=1}
2015-05-05 21:55:42.040 padApp2[71321:10127951] 444 ######## view=<UILayoutContainerView: 0x7973ab20; frame = (0 0; 1024 768); autoresize = W+H; gestureRecognizers = <NSArray: 0x79b1dc30>; layer = <CALayer: 0x7973b410>>
2015-05-05 21:55:46.325 padApp2[71321:10127951] 222 ######## this=<padApp2_d: 0x79730cc0>
2015-05-05 21:55:46.325 padApp2[71321:10127951] 333 ######## rect={X=0,Y=0,Width=1,Height=1}
2015-05-05 21:55:46.326 padApp2[71321:10127951] 444 ######## view=<UILayoutContainerView: 0x7973ab20; frame = (0 0; 1024 768); autoresize = W+H; gestureRecognizers = <NSArray: 0x79b1dc30>; layer = <CALayer: 0x7973b410>>
Comment 3 Sebastien Pouliot 2015-05-05 22:22:53 UTC
Looks like that was just fixed, earlier today, by Rolf's 5e3cc72ee9abb1b06a6796d731b39aedf253c818 on master. My build has this fix and the attached app works correctly.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2015-05-06 04:49:16 UTC

*** This bug has been marked as a duplicate of bug 29720 ***