From 5626740d14554acf7a17a73ec12b0893445832d0 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 12 Jun 2014 08:20:38 +0200 Subject: 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. --- src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/macosx') diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index 485fbd0a0..19a334b75 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -866,7 +866,7 @@ public class MacOSXCGLContext extends GLContextImpl if(DEBUG) { System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable(true): "+attachGLLayerCmd); } - OSXUtil.RunOnMainThread(false, attachGLLayerCmd); + OSXUtil.RunOnMainThread(false, false /* kickNSApp */, attachGLLayerCmd); } else { // -> null == backingLayerHost lastWidth = drawable.getSurfaceWidth(); lastHeight = drawable.getSurfaceHeight(); @@ -893,7 +893,7 @@ public class MacOSXCGLContext extends GLContextImpl if(DEBUG) { System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable(false): "+dCmd); } - OSXUtil.RunOnMainThread(false, dCmd); + OSXUtil.RunOnMainThread(false, true /* kickNSApp */, dCmd); if( null != gl3ShaderProgram ) { gl3ShaderProgram.destroy(MacOSXCGLContext.this.gl.getGL3()); gl3ShaderProgram = null; -- cgit v1.2.3