Bug 39545 - Pretty reliable shutdown crash with 2.8.x
Summary: Pretty reliable shutdown crash with 2.8.x
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: Master
Hardware: PC Mac OS
: --- normal
Target Milestone: 2.8.0 (C7)
Assignee: Rolf Bjarne Kvinge [MSFT]
Depends on:
Reported: 2016-03-11 11:09 UTC by Alan McGovern
Modified: 2016-03-17 10:40 UTC (History)
2 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 Alan McGovern 2016-03-11 11:09:16 UTC
I have mmp (master: 747d23d)

* check out and compile xamarin studio in your terminal
* Open md-addins/Xamarin.Designer.iOS/MTDesigner.sln
* Debug DesignerApp.Gtk
* Drag a scene or two in and then hit File -> Exit

You get a random crash every single time* typically from the finalizer. The actual crash changes a lot. Sometimes it's a native crash, sometimes it's a crash in managed code because our finalizer touches a managed object which tries to re-create the C# wrapper for an object with no IntPtr constructor.

I see no reason why this wouldn't affect XS too, but for the moment it does not seem reproducible there.
Comment 1 Alan McGovern 2016-03-11 11:15:19 UTC
First sample managed crash, can be triggered by dragging a bunch of items from the toolbox to the surface and then exiting. That's the action which instantiates these objects.

2016-03-11 11:10:47.868 mono64[5245:50528] 
Unhandled Exception:
System.Exception: Failed to marshal the Objective-C object 0x7fe718612b20 (type: Xamarin_Designer_Mac_DesignerDragOperationMac_MacDragImage_LayerScaleTransitionDelegate). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Xamarin.Designer.Mac.DesignerDragOperationMac+MacDragImage+LayerScaleTransitionDelegate' does not have a constructor that takes one IntPtr argument).
  at ObjCRuntime.Runtime.MissingCtor (IntPtr ptr, IntPtr klass, System.Type type, MissingCtorResolution resolution) [0x0006e] in <filename unknown>:0 
  at ObjCRuntime.Runtime.ConstructNSObject[T] (IntPtr ptr, System.Type type, MissingCtorResolution missingCtorResolution) [0x0002c] in <filename unknown>:0 
  at ObjCRuntime.Runtime.ConstructNSObject (IntPtr ptr, IntPtr klass, MissingCtorResolution missingCtorResolution) [0x00015] in <filename unknown>:0 
  at ObjCRuntime.Runtime.GetNSObject (IntPtr ptr, MissingCtorResolution missingCtorResolution, Boolean evenInFinalizerQueue) [0x00034] in <filename unknown>:0 
  at Registrar.DynamicRegistrar.GetMethodDescriptionAndObject (System.Type type, IntPtr selector, IntPtr obj, System.IntPtr& mthis) [0x00068] in <filename unknown>:0 
  at ObjCRuntime.Runtime.GetMethodAndObjectForSelector (IntPtr klass, IntPtr sel, IntPtr obj, System.IntPtr& mthis) [0x0000c] in <filename unknown>:0 
  at ObjCRuntime.Runtime.get_method_and_object_for_selector (IntPtr cls, IntPtr sel, IntPtr obj, System.IntPtr& mthis) [0x00001] in <filename unknown>:0 
  at (wrapper native-to-managed) ObjCRuntime.Runtime:get_method_and_object_for_selector (intptr,intptr,intptr,intptr&)
  at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend_IntPtr (intptr,intptr,intptr)
  at CoreAnimation.CALayerDelegate.Dispose (Boolean disposing) [0x00026] in <filename unknown>:0 
  at Foundation.NSObject.Finalize () [0x00001] in <filename unknown>:0
Comment 2 Alan McGovern 2016-03-11 11:15:28 UTC
Two native crashes: https://gist.github.com/alanmcgovern/ce7f7eb0e3b0b7115748
Comment 3 Alan McGovern 2016-03-11 11:17:39 UTC
Rolf suggested this in slack:

Rolf Kvinge @alan: I assume the layer is called `LayerScaleTransition` - can you try overriding its Dispose method, and set Delegate to null and see if that fixes it?

However my concern is that since these objects are being cleaned up by the finalizer then overriding Dispose and trying to null out the Delegate will cause the same lookup problem and same managed exception as in comment 1. We could manually dispose these objects when we're done in order avoid the problem though.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2016-03-17 10:40:18 UTC

maccore/master: 632b998b79c02de4df8d33648055bb3a64c9ff7a
maccore/cycle7: ec425a232c1b15eb5f9db85e521e802ad3dae5c0