Fix crash on resize on Skia/OSX port

Keep NSWindowDelegate reference alive in OSXWindow
This commit is contained in:
David Capello 2015-10-07 10:43:53 -03:00
parent e3f0688945
commit 6e5271848c

View File

@ -19,12 +19,11 @@
she::EventQueue* queue;
OSXWindow* window;
}
- (OSXWindowDelegate*)initWithWindow:(OSXWindow*)window;
- (BOOL)windowShouldClose:(id)sender;
- (void)windowWillClose:(NSNotification *)notification;
- (void)windowDidResize:(NSNotification*)notification;
- (void)windowDidMiniaturize:(NSNotification*)notification;
- (void)setEventQueue:(she::EventQueue*)aQueue;
- (void)setOSXWindow:(OSXWindow*)aWindow;
@end
@interface OSXView : NSView
@ -33,6 +32,13 @@
@implementation OSXWindowDelegate
- (OSXWindowDelegate*)initWithWindow:(OSXWindow*)aWindow
{
window = aWindow;
queue = she::instance()->eventQueue();
return self;
}
- (BOOL)windowShouldClose:(id)sender
{
[window closeDelegate]->notifyClose();
@ -51,16 +57,6 @@
{
}
- (void)setEventQueue:(she::EventQueue*)aQueue
{
queue = aQueue;
}
- (void)setOSXWindow:(OSXWindow*)aWindow
{
window = aWindow;
}
@end
@implementation OSXView
@ -81,10 +77,6 @@
clientSize.w = restoredSize.w = rect.size.width;
clientSize.h = restoredSize.h = rect.size.height;
OSXWindowDelegate* windowDelegate = [[OSXWindowDelegate new] autorelease];
[windowDelegate setEventQueue:she::instance()->eventQueue()];
[windowDelegate setOSXWindow:self];
OSXView* view = [[[OSXView alloc] initWithFrame:rect] autorelease];
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
@ -94,7 +86,7 @@
backing:NSBackingStoreBuffered
defer:NO];
[self setDelegate:windowDelegate];
[self setDelegate:[[OSXWindowDelegate alloc] initWithWindow:self]];
[self setContentView:view];
[self center];
return self;