summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-03-19 00:00:18 +0100
committerSven Gothel <[email protected]>2013-03-19 00:00:18 +0100
commit12e868f79938f44eba6f50313f977be76d8ea2bb (patch)
treed49306c3430ec03152322d365a66bdc6d878e79c /src
parent4457b343fe8eba3f2da096a72e38b1aac978ffd5 (diff)
MyNSOpenGLContext::dealloc: Avoid 'invalid context'
Diffstat (limited to 'src')
-rw-r--r--src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m28
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m8
2 files changed, 29 insertions, 7 deletions
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
index 96783c75d..0f1073c9d 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
@@ -112,18 +112,40 @@ extern GLboolean glIsVertexArray (GLuint array);
#endif
+#ifdef VERBOSE_ON
+ #define CGLRETAINCOUNT(c) (NULL!=c?(int)CGLGetContextRetainCount(c):-1)
+#else
+ #define CGLRETAINCOUNT(c)
+#endif
+
- (void)dealloc
{
+ /**
+ * The explicit CGLContext destruction below
+ * ensures that it is not left behind.
+ * Tests show that w/o these gymnastics, the CGLContext is not freed immediately after calling dealloc.
+ * The retain, release and dealloc ensures [super dealloc] won't message 'invalid context'.
+ */
CGLContextObj cglCtx = [self CGLContextObj];
- DBG_PRINT("MyNSOpenGLContext::dealloc.0 %p (refcnt %d) - CGL-Ctx %p\n", self, (int)[self retainCount], cglCtx);
+ DBG_PRINT("MyNSOpenGLContext::dealloc.0 %p (refcnt %d) - CGL-Ctx %p\n", self, (int)[self retainCount], cglCtx, CGLRETAINCOUNT(cglCtx));
// NSLog(@"MyNSOpenGLContext::dealloc: %@",[NSThread callStackSymbols]);
+
[self clearDrawable];
+ DBG_PRINT("MyNSOpenGLContext.dealloc.1 %d\n", CGLRETAINCOUNT(cglCtx));
if( NULL != cglCtx ) {
- CGLDestroyContext( cglCtx );
+ CGLRetainContext( cglCtx );
+ DBG_PRINT("MyNSOpenGLContext.dealloc.2 %d\n", CGLRETAINCOUNT(cglCtx));
}
[super dealloc];
- // DBG_PRINT("MyNSOpenGLContext.dealloc.X: %p\n", self);
+ DBG_PRINT("MyNSOpenGLContext.dealloc.3 %d\n", CGLRETAINCOUNT(cglCtx));
+ if( NULL != cglCtx ) {
+ CGLReleaseContext( cglCtx );
+ DBG_PRINT("MyNSOpenGLContext.dealloc.4 %d\n", CGLRETAINCOUNT(cglCtx));
+ CGLDestroyContext( cglCtx );
+ DBG_PRINT("MyNSOpenGLContext.dealloc.5 %d\n", CGLRETAINCOUNT(cglCtx));
+ }
+ DBG_PRINT("MyNSOpenGLContext.dealloc.X\n");
}
@end
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m
index 5d292d76e..d6a63702b 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -433,8 +433,8 @@ static void FixCALayerLayout0(MyCALayer* rootLayer, CALayer* subLayer, jint widt
if( NULL != rootLayer ) {
CGRect lRect = [rootLayer frame];
if(lRect.origin.x!=0 || lRect.origin.y!=0 || lRect.size.width!=width || lRect.size.height!=height) {
- DBG_PRINT("CALayer::FixCALayerLayout0.0: Root %p exp 0/0 %dx%d -> frame0: %lf/%lf %lfx%lf\n",
- rootLayer, (int)width, (int)height, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
+ DBG_PRINT("CALayer::FixCALayerLayout0.0: Root %p frame %lf/%lf %lfx%lf -> 0/0 %dx%d\n",
+ rootLayer, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height, (int)width, (int)height);
lRect.origin.x = 0;
lRect.origin.y = 0;
lRect.size.width = width;
@@ -445,8 +445,8 @@ static void FixCALayerLayout0(MyCALayer* rootLayer, CALayer* subLayer, jint widt
if( NULL != subLayer ) {
CGRect lRect = [subLayer frame];
if(lRect.origin.x!=0 || lRect.origin.y!=0 || lRect.size.width!=width || lRect.size.height!=height) {
- DBG_PRINT("CALayer::FixCALayerLayout0.0: SubL %p exp 0/0 %dx%d -> frame0: %lf/%lf %lfx%lf\n",
- subLayer, (int)width, (int)height, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
+ DBG_PRINT("CALayer::FixCALayerLayout0.0: SubL %p frame %lf/%lf %lfx%lf -> 0/0 %dx%d\n",
+ subLayer, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height, (int)width, (int)height);
lRect.origin.x = 0;
lRect.origin.y = 0;
lRect.size.width = width;