diff options
author | Sven Gothel <[email protected]> | 2014-06-12 08:20:38 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-06-12 08:20:38 +0200 |
commit | 5626740d14554acf7a17a73ec12b0893445832d0 (patch) | |
tree | f2d68b4df87f0ecc1946d72e3d84f0b3587d2798 /src/nativewindow/native | |
parent | 94de08a2b0661d072324677c729fc8d1b3d0ef0f (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/nativewindow/native')
-rw-r--r-- | src/nativewindow/native/macosx/OSXmisc.m | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index fa3bf026a..bf01f19d8 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -1006,29 +1006,61 @@ static void RunOnThread (JNIEnv *env, jobject runnable, BOOL onMain, jint delayI DBG_PRINT2( "RunOnThread.X\n"); } -/* +static void OSXUtil_KickNSApp() { + NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined + location: NSMakePoint(0,0) + modifierFlags: 0 + timestamp: 0.0 + windowNumber: 0 + context: nil + subtype: 0 + data1: 0 + data2: 0]; + [NSApp postEvent: event atStart: true]; +} + +/** * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: RunOnMainThread0 * Signature: (ZLjava/lang/Runnable;)V */ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RunOnMainThread0 - (JNIEnv *env, jclass unused, jobject runnable) + (JNIEnv *env, jclass unused, jboolean kickNSApp, jobject runnable) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; RunOnThread (env, runnable, YES, 0); + if( kickNSApp ) { + OSXUtil_KickNSApp(); + } [pool release]; } /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: RunLater0 - * Signature: (ZLjava/lang/Runnable;I)V + * Signature: (ZZLjava/lang/Runnable;I)V */ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RunLater0 - (JNIEnv *env, jclass unused, jboolean onMain, jobject runnable, jint delay) + (JNIEnv *env, jclass unused, jboolean onMain, jboolean kickNSApp, jobject runnable, jint delay) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; RunOnThread (env, runnable, onMain ? YES : NO, delay); + if( kickNSApp ) { + OSXUtil_KickNSApp(); + } + [pool release]; +} + +/** + * Class: Java_jogamp_nativewindow_macosx_OSXUtil + * Method: KickNSApp0 + * Signature: (V)V + */ +JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_KickNSApp0 + (JNIEnv *env, jclass unused) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + OSXUtil_KickNSApp(); [pool release]; } |