diff options
author | Sven Gothel <[email protected]> | 2012-09-16 13:27:06 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-09-16 13:27:06 +0200 |
commit | e30c2c7d06847889d961d12b50e77e4dfd6e525f (patch) | |
tree | e0d280af948f52088e2b072bacf3b6b6469cf456 /src/jogl/native | |
parent | 33896a42dcec55d52030fae33e64fa966c67f91d (diff) |
OSX: Capture 'invalid drawable' message cause by NSOpenGLContext::setView(NULL || incomplete-view) ; Add missing [ctx release] in MyNSOpenGLLayer ; Misc
NSOpenGLContext::setView(NULL || incomplete-view) was called on 2 occasions:
[1] - MacOSXCGLContext native createContext
[2] - NSOpenGLLayer internals
For [1], we simply don't call setView(..) ourselfs in case view is NULL or incomplete (invisible)
For [2], we need to wrap the class 'MyNSOpenGLContext:NSOpenGLContext' and capture setView(NULL)
++
Add missing [ctx release] in MyNSOpenGLLayer, otherwise resource won't get dealloc'ed
+++
Misc:
- MacOSXCGLContext. contextRealized(true): set pbuffer -> ctx, otherwise 1st makeCurrent call will not catch it
- MacOSXOnscreenCGLContext: don't add ContextUpdater to invisible ProxySurface's (dummy window)
Diffstat (limited to 'src/jogl/native')
-rw-r--r-- | src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m | 65 | ||||
-rw-r--r-- | src/jogl/native/macosx/MacOSXWindowSystemInterface.m | 43 |
2 files changed, 93 insertions, 15 deletions
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m index 63323b76d..f3495efff 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m @@ -25,6 +25,56 @@ // // #define DBG_PERF 1 +/** + * Capture setView(NULL), which produces a 'invalid drawable' message + * + * Also track lifecycle via DBG_PRINT messages, if VERBOSE is enabled! + */ +@interface MyNSOpenGLContext: NSOpenGLContext +{ +} +- (id)initWithFormat:(NSOpenGLPixelFormat *)format shareContext:(NSOpenGLContext *)share; +- (void)setView:(NSView *)view; +- (void)update; +- (void)dealloc; + +@end + +@implementation MyNSOpenGLContext + +- (id)initWithFormat:(NSOpenGLPixelFormat *)format shareContext:(NSOpenGLContext *)share +{ + DBG_PRINT("MyNSOpenGLContext.initWithFormat.0: format %p, share %p\n", format, share); + MyNSOpenGLContext * o = [super initWithFormat:format shareContext:share]; + DBG_PRINT("MyNSOpenGLContext.initWithFormat.X: new %p\n", o); + return o; +} + +- (void)setView:(NSView *)view +{ + DBG_PRINT("MyNSOpenGLContext.setView: this.0 %p, view %p\n", self, view); + if(NULL != view) { + [super setView:view]; + } + DBG_PRINT("MyNSOpenGLContext.setView.X\n"); +} + +- (void)update +{ + DBG_PRINT("MyNSOpenGLContext.update: this.0 %p, view %p\n", self, [self view]); + [super update]; + DBG_PRINT("MyNSOpenGLContext.update.X\n"); +} + +- (void)dealloc +{ + DBG_PRINT("MyNSOpenGLContext.dealloc: this.0 %p\n", self); + [super dealloc]; + DBG_PRINT("MyNSOpenGLContext.dealloc.X: %p\n", self); +} + +@end + @interface MyNSOpenGLLayer: NSOpenGLLayer { @private @@ -204,6 +254,8 @@ static const GLfloat gl_verts[] = { [self setOpaque: opaque ? YES : NO]; +#ifdef VERBOSE_ON + CGRect lRect = [self bounds]; if(NULL != pbuffer) { DBG_PRINT("MyNSOpenGLLayer::init (pbuffer) %p, ctx %p, pfmt %p, pbuffer %p, opaque %d, pbuffer %dx%d -> tex %dx%d, bounds: %lf/%lf %lfx%lf (refcnt %d)\n", self, parentCtx, parentPixelFmt, pbuffer, opaque, [pbuffer pixelsWide], [pbuffer pixelsHigh], texWidth, texHeight, @@ -213,6 +265,7 @@ static const GLfloat gl_verts[] = { self, parentCtx, parentPixelFmt, opaque, (int)textureID, texWidth, texHeight, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height, (int)[self retainCount]); } +#endif return self; } @@ -293,9 +346,10 @@ static const GLfloat gl_verts[] = { - (NSOpenGLContext *)openGLContextForPixelFormat:(NSOpenGLPixelFormat *)pixelFormat { - NSOpenGLContext * nctx = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:parentCtx]; - DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat: %p (refcnt %d) - pfmt %p, parent %p -> new-ctx %p\n", - self, (int)[self retainCount], pixelFormat, parentCtx, nctx); + DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat.0: %p (refcnt %d) - pfmt %p, parent %p\n", + self, (int)[self retainCount], pixelFormat, parentCtx); + NSOpenGLContext * nctx = [[MyNSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:parentCtx]; + DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat.X: new-ctx %p\n", nctx); return nctx; } @@ -324,7 +378,7 @@ static const GLfloat gl_verts[] = { if(NULL!=context) { [context makeCurrentContext]; - DBG_PRINT("MyNSOpenGLLayer::deallocPBuffer (with ctx) %p (refcnt %d) - context %p, pbuffer %p, texID %d\n", self, (int)[self retainCount], context, pbuffer, (int)texureID); + DBG_PRINT("MyNSOpenGLLayer::deallocPBuffer (with ctx) %p (refcnt %d) - context %p, pbuffer %p, texID %d\n", self, (int)[self retainCount], context, pbuffer, (int)textureID); if( 0 != textureID ) { glDeleteTextures(1, &textureID); @@ -333,7 +387,7 @@ static const GLfloat gl_verts[] = { [context clearDrawable]; } else { - DBG_PRINT("MyNSOpenGLLayer::deallocPBuffer (w/o ctx) %p (refcnt %d) - context %p, pbuffer %p, texID %d\n", self, (int)[self retainCount], context, pbuffer, (int)texureID); + DBG_PRINT("MyNSOpenGLLayer::deallocPBuffer (w/o ctx) %p (refcnt %d) - context %p, pbuffer %p, texID %d\n", self, (int)[self retainCount], context, pbuffer, (int)textureID); } pbuffer = NULL; [self setTextureID: 0]; @@ -346,6 +400,7 @@ static const GLfloat gl_verts[] = { pthread_mutex_lock(&renderLock); [self disableAnimation]; [self deallocPBuffer]; + [[self openGLContext] release]; [self release]; DBG_PRINT("MyNSOpenGLLayer::releaseLayer.X: %p (refcnt %d)\n", self, (int)[self retainCount]); pthread_mutex_unlock(&renderLock); diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m index becd41bb2..48807ee29 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m @@ -446,7 +446,7 @@ NSOpenGLPixelFormat* createPixelFormat(int* iattrs, int niattrs, int* ivalues) { NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; // if(fmt == nil) { fallback to a [NSOpenGLView defaultPixelFormat] crashed (SIGSEGV) on 10.6.7/NV } - DBG_PRINT("createPixelFormat.X: pfmt %p\n", fmt); + DBG_PRINT("\ncreatePixelFormat.X: pfmt %p\n", fmt); [pool release]; return fmt; @@ -503,7 +503,7 @@ NSView* getNSView(NSOpenGLContext* ctx) { NSOpenGLContext* createContext(NSOpenGLContext* share, NSView* view, - Bool allowIncompleteView, + Bool incompleteView, NSOpenGLPixelFormat* fmt, Bool opaque, int* viewNotReady) @@ -512,13 +512,13 @@ NSOpenGLContext* createContext(NSOpenGLContext* share, getRendererInfo(); - DBG_PRINT("createContext.0: share %p, view %p, allowIncompleteView %d, pixfmt %p, opaque %d\n", - share, view, (int)allowIncompleteView, fmt, opaque); + DBG_PRINT("createContext.0: share %p, view %p, incompleteView %d, pixfmt %p, opaque %d\n", + share, view, (int)incompleteView, fmt, opaque); if (view != nil) { Bool viewReady = true; - if(!allowIncompleteView) { + if(!incompleteView) { if ([view lockFocusIfCanDraw] == NO) { DBG_PRINT("createContext.1 [view lockFocusIfCanDraw] failed\n"); viewReady = false; @@ -527,7 +527,7 @@ NSOpenGLContext* createContext(NSOpenGLContext* share, if(viewReady) { NSRect frame = [view frame]; if ((frame.size.width == 0) || (frame.size.height == 0)) { - if(!allowIncompleteView) { + if(!incompleteView) { [view unlockFocus]; } DBG_PRINT("createContext.2 view.frame size %dx%d\n", (int)frame.size.width, (int)frame.size.height); @@ -557,8 +557,10 @@ NSOpenGLContext* createContext(NSOpenGLContext* share, GLint zeroOpacity = 0; [ctx setValues:&zeroOpacity forParameter:NSOpenGLCPSurfaceOpacity]; } - [ctx setView:view]; - if(!allowIncompleteView) { + if(!incompleteView) { + DBG_PRINT("createContext.3.0: setView\n"); + [ctx setView:view]; + DBG_PRINT("createContext.3.X: setView\n"); [view unlockFocus]; } } @@ -628,7 +630,12 @@ void setContextOpacity(NSOpenGLContext* ctx, int opacity) { void updateContext(NSOpenGLContext* ctx) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - [ctx update]; + NSView *nsView = [ctx view]; + if(NULL != nsView) { + DBG_PRINT("updateContext.0: ctx %p, ctx.view %p\n", ctx, nsView); + [ctx update]; + DBG_PRINT("updateContext.X\n"); + } [pool release]; } @@ -638,7 +645,10 @@ void copyContext(NSOpenGLContext* dest, NSOpenGLContext* src, int mask) { void* updateContextRegister(NSOpenGLContext* ctx, NSView* view) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + DBG_PRINT("updateContextRegister.0: ctx %p, view %p\n", ctx, view); ContextUpdater *contextUpdater = [[ContextUpdater alloc] initWithContext: ctx view: view]; + DBG_PRINT("updateContextRegister.X: ctxupd %p\n", contextUpdater); [pool release]; return contextUpdater; } @@ -658,47 +668,60 @@ void updateContextUnregister(void* updater) { ContextUpdater *contextUpdater = (ContextUpdater *)updater; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + DBG_PRINT("updateContextUnregister.0: ctxupd %p\n", contextUpdater); [contextUpdater release]; + DBG_PRINT("updateContextUnregister.X\n"); [pool release]; } NSOpenGLPixelBuffer* createPBuffer(int renderTarget, int internalFormat, int width, int height) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + DBG_PRINT("createPBuffer.0: renderTarget 0x%x, ifmt 0x%x, %dx%d: \n", renderTarget, internalFormat, width, height); NSOpenGLPixelBuffer* pBuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:renderTarget textureInternalFormat:internalFormat textureMaxMipMapLevel:0 pixelsWide:width pixelsHigh:height]; + DBG_PRINT("createPBuffer.X: res %p\n", pBuffer); [pool release]; return pBuffer; } Bool destroyPBuffer(NSOpenGLPixelBuffer* pBuffer) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + DBG_PRINT("destroyPBuffer.0: pbuffer %p\n", pBuffer); [pBuffer release]; + DBG_PRINT("destroyPBuffer.X\n"); [pool release]; return true; } void setContextPBuffer(NSOpenGLContext* ctx, NSOpenGLPixelBuffer* pBuffer) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + DBG_PRINT("setContextPBuffer.0: ctx %p, pbuffer %p\n", ctx, pBuffer); [ctx setPixelBuffer: pBuffer cubeMapFace: 0 mipMapLevel: 0 currentVirtualScreen: [ctx currentVirtualScreen]]; + DBG_PRINT("setContextPBuffer.X\n"); [pool release]; } void setContextTextureImageToPBuffer(NSOpenGLContext* ctx, NSOpenGLPixelBuffer* pBuffer, GLenum colorBuffer) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + DBG_PRINT("setContextTextureImageToPBuffer.0: ctx %p, pbuffer %p, colorBuffer 0x%x\n", ctx, pBuffer, (int)colorBuffer); [ctx setTextureImageToPixelBuffer: pBuffer colorBuffer: colorBuffer]; + DBG_PRINT("setContextTextureImageToPBuffer.X\n"); [pool release]; } Bool isNSOpenGLPixelBuffer(uint64_t object) { NSObject *nsObj = (NSObject*) (intptr_t) object; - return [nsObj isMemberOfClass:[NSOpenGLPixelBuffer class]]; + DBG_PRINT("isNSOpenGLPixelBuffer.0: obj %p\n", object); + Bool res = [nsObj isMemberOfClass:[NSOpenGLPixelBuffer class]]; + DBG_PRINT("isNSOpenGLPixelBuffer.X: res %d\n", (int)res); + return res; } #include <mach-o/dyld.h> |