Skip to content

Instantly share code, notes, and snippets.

@mhutch

mhutch/crashy.cs Secret

Created Oct 11, 2016
Embed
What would you like to do?
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