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
This commit is contained in:
Daniel Collin 2016-07-31 18:05:11 +02:00
parent 31215a5b21
commit 26d41d1d07

View file

@ -24,20 +24,20 @@
- (void)drawRect:(NSRect)rect - (void)drawRect:(NSRect)rect
{ {
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, draw_buffer, width * height * 4, NULL); CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, draw_buffer, width * height * 4, NULL);
CGImageRef img = CGImageCreate(width, height, 8, 32, width * 4, space, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, CGImageRef img = CGImageCreate(width, height, 8, 32, width * 4, space, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little,
provider, NULL, false, kCGRenderingIntentDefault); provider, NULL, false, kCGRenderingIntentDefault);
CGColorSpaceRelease(space); CGColorSpaceRelease(space);
CGDataProviderRelease(provider); 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 - (void)viewDidMoveToWindow
{ {
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowResized:) name:NSWindowDidResizeNotification selector:@selector(windowResized:) name:NSWindowDidResizeNotification
object:[self window]]; object:[self window]];
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc - (void)dealloc
{ {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc]; [super dealloc];
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)windowResized:(NSNotification *)notification; - (void)windowResized:(NSNotification *)notification;
{ {
NSSize size = [self bounds].size; NSSize size = [self bounds].size;
OSXWindow* window = (OSXWindow*)[self window]; 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 @end