From 26d41d1d070365f709fc3cfa05768ad5ab473455 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Sun, 31 Jul 2016 18:05:11 +0200 Subject: [PATCH] Fixed crash on Mac for large Windows In some cases a resize event can happen before we have setup our user-data. Now we make sure that user data is present before using it Closes #26 --- src/native/macosx/OSXWindowFrameView.m | 37 ++++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/native/macosx/OSXWindowFrameView.m b/src/native/macosx/OSXWindowFrameView.m index b5dd20d..5b3a992 100644 --- a/src/native/macosx/OSXWindowFrameView.m +++ b/src/native/macosx/OSXWindowFrameView.m @@ -24,20 +24,20 @@ - (void)drawRect:(NSRect)rect { - CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; + CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; - CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); - CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, draw_buffer, width * height * 4, NULL); + CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); + CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, draw_buffer, width * height * 4, NULL); - CGImageRef img = CGImageCreate(width, height, 8, 32, width * 4, space, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, - provider, NULL, false, kCGRenderingIntentDefault); + CGImageRef img = CGImageCreate(width, height, 8, 32, width * 4, space, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, + provider, NULL, false, kCGRenderingIntentDefault); - CGColorSpaceRelease(space); - CGDataProviderRelease(provider); + CGColorSpaceRelease(space); + CGDataProviderRelease(provider); - CGContextDrawImage(context, CGRectMake(0, 0, width * scale, height * scale), img); + CGContextDrawImage(context, CGRectMake(0, 0, width * scale, height * scale), img); - CGImageRelease(img); + CGImageRelease(img); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -109,27 +109,30 @@ - (void)viewDidMoveToWindow { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(windowResized:) name:NSWindowDidResizeNotification - object:[self window]]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(windowResized:) name:NSWindowDidResizeNotification + object:[self window]]; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (void)windowResized:(NSNotification *)notification; { - NSSize size = [self bounds].size; + NSSize size = [self bounds].size; OSXWindow* window = (OSXWindow*)[self window]; - window->shared_data->width = (int)(size.width); - window->shared_data->height = (int)(size.height); + + if (window->shared_data) { + window->shared_data->width = (int)(size.width); + window->shared_data->height = (int)(size.height); + } } @end