From b0cb7e5faf5f0b5a7f4cfe31e49be9342b36e0a3 Mon Sep 17 00:00:00 2001 From: Gerard Ziemski Date: Tue, 4 Nov 2003 19:27:09 +0000 Subject: Print error messages when nsview is not a valid drawable and return NULL from createContext git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@70 232f8b59-042b-4e1e-8c03-345bb8c30851 --- src/native/jogl/MacOSXWindowSystemInterface.m | 28 ++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/native/jogl/MacOSXWindowSystemInterface.m b/src/native/jogl/MacOSXWindowSystemInterface.m index 3d852571c..2d812ec58 100644 --- a/src/native/jogl/MacOSXWindowSystemInterface.m +++ b/src/native/jogl/MacOSXWindowSystemInterface.m @@ -16,6 +16,23 @@ void* createContext(void* shareContext, void* view) NSOpenGLContext *nsChareCtx = (NSOpenGLContext*)shareContext; NSView *nsView = (NSView*)view; + if (nsView != NULL) + { + NSRect frame = [nsView frame]; + if ((frame.size.width == 0) || (frame.size.height == 0)) + { + fprintf(stderr, "Error: empty view at \"%s:%s:%d\"\n", __FILE__, __FUNCTION__, __LINE__); + // the view is not ready yet + return NULL; + } + else if ([nsView lockFocusIfCanDraw] == NO) + { + fprintf(stderr, "Error: view not ready at \"%s:%s:%d\"\n", __FILE__, __FUNCTION__, __LINE__); + // the view is not ready yet + return NULL; + } + } + if (gAutoreleasePool == NULL) { gAutoreleasePool = [[NSAutoreleasePool alloc] init]; @@ -41,7 +58,7 @@ void* createContext(void* shareContext, void* view) if (nsView == NULL) { - attribs[12] = 0; // no stencil, no accums fo pBuffers + attribs[12] = 0; // no stencil, no accums for pBuffers } NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; @@ -49,15 +66,16 @@ void* createContext(void* shareContext, void* view) NSOpenGLContext* nsContext = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nsChareCtx]; [fmt release]; - + if (nsView != nil) { - [nsContext setView: nsView]; + [nsContext setView:nsView]; + + [nsView unlockFocus]; } - + [nsContext retain]; -//fprintf(stderr, " nsContext=%p\n", nsContext); return nsContext; } -- cgit v1.2.3