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
{
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