Bug 25873 - Unified API NSWindow Adding a WillClose Event Causes Resizing to Fail
Summary: Unified API NSWindow Adding a WillClose Event Causes Resizing to Fail
Status: VERIFIED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.11.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 2.0.x
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2015-01-09 09:18 UTC by David Lilley
Modified: 2015-02-27 08:20 UTC (History)
3 users (show)

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


Attachments
Self Contained Tests for Unified and Classic (14.67 KB, application/zip)
2015-01-09 09:18 UTC, David Lilley
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 David Lilley 2015-01-09 09:18:48 UTC
Created attachment 9300 [details]
Self Contained Tests for Unified and Classic

Adding A WillClose Event on a Window will cause the Reszing of a Window to Fail...The Window dissappears but the Application Hangs with out crashing or logs

See Attachment

Console 
output 09/01/15 15:11:20,292 WindowServer[117]: disable_update_timeout: UI updates were forcibly disabled by application "MacBanking" for over 1.00 seconds. Server has re-enabled them.

See Sample for NSPanel and NSWindow



=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 974acce5-5296-4842-81d8-fad813eef863
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: 8.6.0.50 (Business Edition)
Hash: 561dfed
Branch: 
Build date: 2015-01-06 17:56:14-0500

=== Xamarin.Android ===

Not Installed

=== Xamarin.Mac ===

Version: 1.11.3.0 (Business Edition)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.10.2
Darwin Davids-iMac.local 14.1.0 Darwin Kernel Version 14.1.0
    Sun Dec 28 21:20:58 PST 2014
    root:xnu-2782.10.72~3/RELEASE_X86_64 x86_64
Comment 1 Chris Hamons 2015-01-09 10:55:29 UTC
I'm actually seeing crashes in this app: https://gist.github.com/chamons/66dbf2726ae293c09ee1

I'm not seeing crashes in Alpha, but the events are still not working.

Our C# event exposed API is flaky. My rework should make things better possibly.

Until then, you should be able to work around this by assigning a delegate your your panel and overriding the relevant methods instead of using the c# events David.
Comment 2 Jon Goldberger [MSFT] 2015-01-26 08:26:33 UTC
I am seeing this too, I think. With every event handler that I have tested, the app crashes when the event is fired. For example adding the following to AwakeFromNib() in a Unified API Xamarin.Mac template causes a crash when you resize the window:

Window.DidResize += (object sender, EventArgs e) => { };

For all of he events I tested, the app crashed even if that particular event wasn't firing, so if I attached the WillClose event instead of the DidResize event above, the app still crashed when I resized the window. 

### Stacktrace:

>  at <unknown> <0xffffffff>
>  at (wrapper managed-to-native) ObjCRuntime.Messaging.IntPtr_objc_msgSend (intptr,intptr) <IL 0x00012, 0xffffffff>
>  at ObjCRuntime.Runtime.GetNSObject (intptr) [0x00070] in /Users/builder/data/lanes/xamcore-lion-1.10-branch/2ff3e7b7/source/xamcore/maccore/src/ObjCRuntime/Runtime.mac.cs:205
>  at ObjCRuntime.NSObjectMarshaler`1.MarshalNativeToManaged (intptr) [0x00002] in /Users/builder/data/lanes/xamcore-lion-1.10-branch/2ff3e7b7/source/xamcore/maccore/src/ObjCRuntime/NSObjectMarshaler.cs:35
>  at (wrapper native-to-managed) object.[AppKit.NSWindow+_NSWindowDelegate.CoreGraphics.CGSize WillResize(AppKit.NSWindow, CoreGraphics.CGSize)] (intptr,Foundation.NSObject,ObjCRuntime.Selector,AppKit.NSWindow,CoreGraphics.CGSize) <IL 0x000bd, 0xffffffff>
>  at <unknown> <0xffffffff>
>  at (wrapper managed-to-native) AppKit.NSApplication.NSApplicationMain (int,string[]) <IL 0x00093, 0xffffffff>
>  at AppKit.NSApplication.Main (string[]) [0x00041] in /Users/builder/data/lanes/xamcore-lion-1.10-branch/2ff3e7b7/source/xamcore/src/AppKit/NSApplication.cs:105
>  at TestWindowDidResize.MainClass.Main (string[]) [0x00007] in /Users/apple/Downloads/TestWindowDidResize/TestWindowDidResize/Main.cs:12
>  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>


### My Version Info:
=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: 8.6.0.51 (Business Edition)
Hash: dfb682f
Branch: 
Build date: 2015-01-08 13:39:32-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		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.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.10.1
Darwin Jons-iMac.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 5 Jon Goldberger [MSFT] 2015-01-26 08:41:55 UTC
Just updated to Alpha Version: 1.12.0.4

Attaching the DidResize event to the Window as in comment 2, the app did not crash, the event fired, the handler executed, but the Window disappeared and was nowhere to be found. It still showed up in the Window list in the Mac OS X Menu, but Bring All TO Front did not do anything and minimizing all other windows did not reveal it anywhere. It was just gone. 

No stack trace or error was thrown that I saw. and the app is technically still running.

Yup, a window delegate is the way to go for now.
Comment 6 Chris Hamons 2015-02-24 14:53:14 UTC
This appears to work in master after my delegate/generator changes. I'm hitting the sdfsf print on close and no crashes.
Comment 7 Naqeeb 2015-02-27 08:20:05 UTC
I have checked this issue with Xamarin.Mac 1.13.1.397 and It working fine without any crash.

Hence closing this issue.

Screencast: http://www.screencast.com/t/5h3dsBHxe0

Environment info: 
=== Xamarin Studio ===

Version 5.8 (build 1033)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 4.0.0 ((detached/2634099)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000017

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: 8.6.2.22 (Business Edition)
Hash: 862702c
Branch: 
Build date: 2015-02-18 15:19:23-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		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.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

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

=== Xamarin.Mac ===

Version: 1.13.1.397 (Business Edition)

=== Build Information ===

Release ID: 508001033
Git revision: e8120ebd0c9ee45a83e48ae431e65797c172403f
Build date: 2015-02-26 13:09:22-05
Xamarin addins: e88a2212bb7156a42ad6728b82e99846c3eea817

=== 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