Bug 54919 - NSFormatter subclass sample does not work in static registrar
Summary: NSFormatter subclass sample does not work in static registrar
Status: VERIFIED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Runtime ()
Version: 3.2.0 (15.1)
Hardware: PC Mac OS
: Normal normal
Target Milestone: 15.3
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-04-10 10:12 UTC by Maxim Kosov
Modified: 2017-07-04 12:46 UTC (History)
5 users (show)

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


Attachments
app with reproduce and a crash log (371.44 KB, application/zip)
2017-04-10 10:12 UTC, Maxim Kosov
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:
VERIFIED FIXED

Description Maxim Kosov 2017-04-10 10:12:07 UTC
Created attachment 21382 [details]
app with reproduce and a crash log

NSTextField with custom NSFormatter crashes application when compiled in Release mode after update to Xamarin.Mac 3.2.0.175
Works in Debug mode. Worked more than half a year before the update.

How to reproduce:
1. Create subclass of NSFormatter
2. Add NSTextField to the UI
3. Add NSFormatter to created text field (no matter how to add: manually with code or IB)
4. Compile and run in Release. Input any character into created text field.

Actual result:
Application crashes (crash log and sample app in attachments)
Comment 1 Chris Hamons 2017-04-10 14:44:01 UTC
In 3.2 a few defaults in Xamarin.Mac were changed:

https://developer.xamarin.com/releases/mac/xamarin.mac_3/xamarin.mac_3.2/#Release_Mode_MMP_Default_Changes

and one of them (use of the static registrar) is the culprit here.

You can swap back to the old behavior by adding 

--registrar=dynamic

to your Project Options -> Build -> Mac Build -> Additional mmp arguments section.

I'll have to look into what the static registrar isn't playing nicely with NSFormatter subclasses.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2017-05-18 12:08:36 UTC
GetObjectValue is defined as this:

    [Export ("getObjectValue:forString:errorDescription:")]
    bool GetObjectValue (out NSObject obj, string str, out NSString error);

and is called with "pointer, pointer, NULL":

frame #1: 0x00000001096e85a6 NSFormatterCrash`::-[CustomFormatter getObjectValue:forString:errorDescription:](self=0x0000610000037680, _cmd="getObjectValue:forString:errorDescription:", p0=0x00007fff568597e0, p1=class name = NSBigMutableString, p2=0x0000000000000000) at registrar.m:37453

the problem is that C# requires "out" parameters to be non-null, so the static registrar assumes the same thing, and does generates this upon returning from the managed function to copy the out parameters back to native code:

-> 21008		*p2 = (id) handle2;

which crashes, since "p2 = NULL".
Comment 3 Rolf Bjarne Kvinge [MSFT] 2017-05-18 13:55:37 UTC
master: https://github.com/xamarin/xamarin-macios/pull/2106