summaryrefslogtreecommitdiffstats
path: root/src/jogl/native
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-06-12 08:20:38 +0200
committerSven Gothel <[email protected]>2014-06-12 08:20:38 +0200
commit5626740d14554acf7a17a73ec12b0893445832d0 (patch)
treef2d68b4df87f0ecc1946d72e3d84f0b3587d2798 /src/jogl/native
parent94de08a2b0661d072324677c729fc8d1b3d0ef0f (diff)
Fix Bug 1019 - Remedy of Bug 691 causes 'access/modify after free' and crashes the app
The 'magic' MyNSOpenGLContext::dealloc (MacOSXWindowSystemInterface-calayer.m) of force destroying the underlying CGLContextObj of it's associated NSOpenGLContext as introduced as a remedy of Bug 691 is plain wrong. It was added in commit f6e6fab2a7ddfb5c9b614cb072c27ff697629161 to mitigate the experience behavior of delayed GL context destruction when creating/destroying them multiple times as exposed in unit test TestGLCanvasAddRemove01SwingAWT. While this 'hack' worked for some reason on some OSX versions, it caused a 'access/modify after free' issue exposed under some circumstances and crashes the application. The actual culprit of the delayed GL context destruction is different. The offthread CALayer detachment and hence final destruction issued on the main-thread is _not_ issued immediately due to some referencing holding by NSApp. Issuing an empty event on the NSApp (thread) will wake up the thread and release claimed resources. This has been found while realizing that the GL context are released if the mouse is being moved (duh!). This issue is also known when triggering stop on the NSApp (NEWT MainThread), same remedy has been implemented here for a long time.
Diffstat (limited to 'src/jogl/native')
-rw-r--r--src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m29
1 files changed, 2 insertions, 27 deletions
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
index 652b0545e..d83ddbc22 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
@@ -112,39 +112,14 @@ 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, CGLRETAINCOUNT(cglCtx));
+ DBG_PRINT("MyNSOpenGLContext::dealloc.0 %p (refcnt %d)\n", self, (int)[self retainCount]);
// NSLog(@"MyNSOpenGLContext::dealloc: %@",[NSThread callStackSymbols]);
[self clearDrawable];
- DBG_PRINT("MyNSOpenGLContext::dealloc.1 %d\n", CGLRETAINCOUNT(cglCtx));
- if( NULL != cglCtx ) {
- CGLRetainContext( cglCtx );
- DBG_PRINT("MyNSOpenGLContext::dealloc.2 %d\n", CGLRETAINCOUNT(cglCtx));
- }
+
[super dealloc];
- 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");
}