-
-
Save mhutch/6a372cea19fab93df18ee99df5f4941c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using AppKit; | |
using Foundation; | |
namespace HelloMac | |
{ | |
//TO REPRO: | |
// 1. Click on the botton | |
// 2. Close the window that pops up | |
// May have to repeat 2-3 times | |
public partial class ViewController : NSViewController | |
{ | |
public ViewController (IntPtr handle) : base (handle) { } | |
public override void ViewDidLoad () | |
{ | |
base.ViewDidLoad (); | |
base.View.AddSubview (NSButton.CreateButton ("Crash me", OpenChildWindow)); | |
} | |
void OpenChildWindow () | |
{ | |
var windowDelegate = new CrashyDelegate (); | |
var frame = View.Window.Frame; | |
frame.Offset (20, 20); | |
NSWindow win = new NSWindow (frame, NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable, NSBackingStore.Buffered, true) { | |
WeakDelegate = windowDelegate | |
}; | |
NSApplication.SharedApplication.RunModalForWindow (win); | |
GC.Collect (); | |
} | |
class CrashyDelegate : NSWindowDelegate | |
{ | |
public override void WillClose (NSNotification notification) | |
{ | |
// uncomment this line to fix the crash | |
// notification.DangerousRetain (); | |
NSApplication.SharedApplication.StopModal (); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment