Bug 29447 - Native Crash when calling GetGlyphRange()
Summary: Native Crash when calling GetGlyphRange()
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 2.0.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 2.0.1 (C5SR1)
Assignee: Chris Hamons
Depends on:
Reported: 2015-04-27 20:47 UTC by Jon Goldberger [MSFT]
Modified: 2015-05-01 07:28 UTC (History)
6 users (show)

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

Test Project (16.22 KB, application/zip)
2015-04-27 20:47 UTC, Jon Goldberger [MSFT]

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 Jon Goldberger [MSFT] 2015-04-27 20:47:53 UTC
Created attachment 10929 [details]
Test Project

## Description

Calling this method on an NSLayoutManager: 


where textContainer is a NSTextContainer. This is a Unified API project. 

## Steps to reproduce

1. Open that attached test project in Xamarin Studio using the current Alpha/Beta builds as noted in the version information below.

2. Click the button

Expected result: The app will continue to run.

Actual Result: App crashes with Native crash. 

Regression Status: Works in Xam.Mac (current stable), breaks in Xam.Mac (current Alpha/Beta)

## Notes

Wrapping the call (line 55 in MainWindowController.cs) in a try/catch does not catch the exception. 
I also tried holding a reference to all of the local variables in the heightForStringDrawing method to try to make sure that no needed objects were disposed. Results were the same. 

## Stack Trace:

>  at <unknown> <0xffffffff>
>  at (wrapper managed-to-native) ObjCRuntime.Messaging.NSRange_objc_msgSend_IntPtr (intptr,intptr,intptr) <IL 0x0002f, 0xffffffff>
>  at AppKit.NSLayoutManager.GetGlyphRange (AppKit.NSTextContainer) [0x0005d] in /Users/builder/data/lanes/1503/8a0e7bca/source/maccore/src/build/mac/full/AppKit/NSLayoutManager.g.cs:762
>  at GlyphCrash.MainWindowController.heightForStringDrawing (string,System.nfloat) [0x00072] in /Users/apple/Downloads/GlyphCrash/GlyphCrash/MainWindowController.cs:60
>  at GlyphCrash.MainWindowController.didTapButton (Foundation.NSObject) [0x00023] in /Users/apple/Downloads/GlyphCrash/GlyphCrash/MainWindowController.cs:47
>  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <IL 0x00062, 0xffffffff>
>  at <unknown> <0xffffffff>
>  at (wrapper managed-to-native) AppKit.NSApplication.NSApplicationMain (int,string[]) <IL 0x000ac, 0xffffffff>
>  at AppKit.NSApplication.Main (string[]) [0x00041] in /Users/builder/data/lanes/1503/8a0e7bca/source/maccore/src/AppKit/NSApplication.cs:94
>  at GlyphCrash.MainClass.Main (string[]) [0x00007] in /Users/apple/Downloads/GlyphCrash/GlyphCrash/Main.cs:12
>  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00060, 0xffffffff>
>Native stacktrace:
>Debug info from gdb:
>Attaching to process 6683.
>/tmp/mono-gdb-commands.vBGlMN:1: Error in sourced command file:
>Unable to attach to process-id 6683: No child processes (10)
>Got a SIGSEGV while executing native code. This usually indicates
>a fatal error in the mono runtime or one of the native libraries 
>used by your application.

## Environment:

=== Xamarin Studio ===

Version 5.9 (build 431)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
	Mono 4.0.0 ((detached/d136b79)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000143

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.3.1 (7703)
Build 6D1002

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 6481535
Branch: master
Build date: 2015-04-27 04:38:13-0400

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509000431
Git revision: 7560726734fc7267de2fa9abed2509968deefaa8
Build date: 2015-04-17 19:25:48-04
Xamarin addins: 2e772c734ab3148054eae7bf8949f340fdeb5e5e

=== Operating System ===

Mac OS X 10.10.3
Darwin Jons-iMac.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 2 Jon Goldberger [MSFT] 2015-04-27 21:42:54 UTC
Additional note:

Project is targeting i386. Issue does not occur if targeting x86_64.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2015-04-29 06:56:22 UTC
The problem is that the 64-bit version of Xamarin.Mac.dll is used.

Here's a tentative PR that fixes it: https://github.com/xamarin/maccore/pull/159.

A potential workaround would be to copy /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/i386/full/Xamarin.Mac.dll to the app after the build (this could probably be done with a AfterBuild msbuild target in the project file).
Comment 4 Rolf Bjarne Kvinge [MSFT] 2015-04-30 08:33:58 UTC
I merged the PR, so that we can try to get the fix in SR1.

maccore/master: 61a9d2575b85e1bdd4f1953cf089b4ea57c490eb
Comment 6 Rajneesh Kumar 2015-04-30 11:46:08 UTC
I have checked this issue with the following builds:

Xamarin Studio Version 5.9 (build 456)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Mono 4.0.1 ((detached/373d684)
GTK+ 2.24.23 (Raleigh theme)
Package version: 400000009
Apple Developer Tools Xcode 6.2 (6776)
Build 6C131e
Xamarin.Mac Version: (Business Edition)
=== Build Information ===
Release ID: 509000456
Git revision: 2666387bc794c06828a59aa95d2435714f732b12
Build date: 2015-04-29 08:16:42-04
Xamarin addins: df9b5918c9f7aca6da509fe3e5a62553aa101910
Operating System Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
Sun Aug 17 19:50:11 PDT 2014
root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64

To check this issue I run the attached test sample and click on the button, and I observed that this issue is working fine. Now the app continues run without any crash. Here is the screencast for the same: http://www.screencast.com/t/dirrEuEW

This issue has been fixed hence, I am closing this issue.

Comment 7 Rolf Bjarne Kvinge [MSFT] 2015-04-30 13:16:04 UTC

maccore/macios-cycle5: fda9314b093434ad2fb8f24bc4392e3851acbd79
Comment 8 Rajneesh Kumar 2015-05-01 07:28:33 UTC
I have checked this issue with the latest Cycle5 builds( XS 5.9 (build 457) + XM + Mono and observed that this is working fine with this builds without any crash.
Here is the screencast: http://www.screencast.com/t/2AwTNqr5Ig