Bug 31771 - unexpected message crash, potentially from AVCaptureFileOutputRecordingDelegate in release mode
Summary: unexpected message crash, potentially from AVCaptureFileOutputRecordingDelega...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: Master
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-07-08 20:19 UTC by Brad Moore
Modified: 2015-07-17 11:24 UTC (History)
2 users (show)

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


Attachments
Test project (16.41 KB, application/zip)
2015-07-08 20:19 UTC, Brad Moore
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 FIXED

Description Brad Moore 2015-07-08 20:19:23 UTC
Am currently working on an app which part of its requirement is to record video from a webcam and then save it to a file for editing. Currently the system works great but when I built a .pkg for the client they told me it crashes when they click the button to finish recording. Turns out release mode does not work for saving the footage.

I am using an AVCaptureMovieFileOutput to save my video from the webcam. It appears calling the StopRecording() method of my object causes it to crash. Can't put a try/catch around it. The movie output file has a method called StartRecordingToOutputFile which is used to start the recording which either takes a NSUrl to an output file and an IAVCaptureFileOutputRecordingDelegate OR a NSUrl to an output file and 2 delegates. One for DidStartRecording and one for FinishedRecording (the two methods in a IAVCaptureFileOutputRecordingDelegate). I have tried 3 ways to implement the delegates. I have tried adding ", IAVCaptureFileOutputRecordingDelegate" to my class definition (unsure if this is called inheriting or not, is placed right after my : NSView however) and adding the appropriate functions. I have tried subclassing AVCaptureFileOutputRecordingDelegate in a RecordingDelegate class, and I have implemented the two delegates directly into my function call. All three ways crash with the same thing, so I don't think either is the incorrect way to do it.

As this is crashing in release mode, debugger wouldn't tell me anything so I had to use the console app to find out what was happening. The crash I receive is,

unexpected message { count = 1, contents =
"XPCErrorDescription" => { length = 18, contents = "Connection invalid" }
}>

and the sender is CoreServicesUIAgent. The very next line tells me that my app

Service exited with abnormal code: 1

The only workaround I have found at the moment is to change my linker behaviour from link SDK to don't link.

I have attached a sample project which shows this issue.
Comment 1 Brad Moore 2015-07-08 20:19:46 UTC
Created attachment 11948 [details]
Test project
Comment 2 Chris Hamons 2015-07-09 11:26:00 UTC
Thanks for the great repro case.

The relevant log:

System.Exception: Failed to marshal the Objective-C object 0x1018df800 (type: AVCaptureConnection). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Foundation.NSObject[]' does not have a constructor that takes one IntPtr argument).
  at ObjCRuntime.Runtime.MissingCtor (IntPtr ptr, IntPtr klass, System.Type type, MissingCtorResolution resolution) [0x00000] in <filename unknown>:0 
  at ObjCRuntime.Runtime.ConstructNSObject[NSObject] (IntPtr ptr, System.Type type, MissingCtorResolution missingCtorResolution) [0x00000] in <filename unknown>:0 
  at ObjCRuntime.Runtime.GetNSObject (IntPtr ptr, System.Type target_type, MissingCtorResolution missingCtorResolution, Boolean evenInFinalizerQueue, System.Boolean& created) [0x00000] in <filename unknown>:0 
  at ObjCRuntime.Runtime.GetNSObjectWithType (IntPtr ptr, IntPtr type_ptr, System.Boolean& created) [0x00000] in <filename unknown>:0 
  at ObjCRuntime.Runtime.WARNING: The runtime version supported by this application is unavailable.
Comment 3 Chris Hamons 2015-07-09 11:34:17 UTC
Since you provided a repro case, it was simple to get you a work around.

Create an xml file with the following contents:

https://gist.github.com/chamons/d6a42bee0de99aad3143

and in the additional mmp arguments (under Mac Build) add:

--xml=linker.xml (or whatever file you created)

That will instruct the linker to stay away from everything in AVFoundation (which stops the crash until we fix the linker).
Comment 4 Rolf Bjarne Kvinge [MSFT] 2015-07-17 11:24:21 UTC
Fixed.

maccore/master: 59c16050a97ab64ff60710910374a0aad50c91e2