diff options
author | Sven Gothel <[email protected]> | 2012-04-21 21:11:35 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-04-21 21:11:35 +0200 |
commit | 6bcfe5e3b60782c4bb047117c12579ff15c961a1 (patch) | |
tree | 667e51830a2d622b23769a9eb0f4c5f257beadc2 /src/newt/native/MacWindow.m | |
parent | 89304ecb034b2c2778f09423cb6d66d084074e11 (diff) |
Newt/OSX(native): close0() shall not release NewtMacWindow (NSWindow) in case it's already in destruction (destroyNotifySend via windowWillClose())
This fixes the double release crash of the NSWindow, at the end of an application.
Tested on OSX 10.6.8 and 10.7.3.
Diffstat (limited to 'src/newt/native/MacWindow.m')
-rw-r--r-- | src/newt/native/MacWindow.m | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index 6d7978895..5a35973cd 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -700,17 +700,17 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacWindow_close0 NewtMacWindow* mWin = (NewtMacWindow*) ((intptr_t) window); NewtView* mView = (NewtView *)[mWin contentView]; NSWindow* pWin = [mWin parentWindow]; - DBG_PRINT( "windowClose.0 - %p,%d view %p,%d, parent %p\n", - mWin, getRetainCount(mWin), mView, getRetainCount(mView), pWin); + BOOL destroyNotifySent = (NULL != mView) ? [mView getDestroyNotifySent] : false; + + DBG_PRINT( "windowClose.0 - %p,%d, destroyNotifySent %d, view %p,%d, parent %p\n", + mWin, getRetainCount(mWin), destroyNotifySent, mView, getRetainCount(mView), pWin); if(NULL!=mView) { + // cleanup view jobject javaWindowObject = [mView getJavaWindowObject]; - if( false == [mView getDestroyNotifySent] ) { - [mView setDestroyNotifySent: true]; - } else if(NULL!=javaWindowObject) { - DBG_PRINT( "windowClose.Error: javaWindowObject not NULL (%p), destroyNotifySent==true\n", javaWindowObject); - } + [mView setDestroyNotifySent: true]; if(NULL!=javaWindowObject) { + DBG_PRINT( "windowClose.0: Clear global javaWindowObject reference (%p)\n", javaWindowObject); (*env)->DeleteGlobalRef(env, javaWindowObject); [mView setJavaWindowObject: NULL]; } @@ -737,15 +737,19 @@ NS_ENDHANDLER DBG_PRINT( "windowClose.1 - %p,%d view %p,%d, parent %p\n", mWin, getRetainCount(mWin), mView, getRetainCount(mView), pWin); - // '[mWin close]' causes a crash at exit. - // This probably happens b/c it sends events to the main loop - // but our resources are gone ?! - // However, issuing a simple release seems to work quite well. - // [mWin release]; - [mWin performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO]; + // Only release window, if release is not yet in process. + // E.g. destroyNotifySent:=true set by NewtMacWindow::windowWillClose(), i.e. window-close was clicked. + if(!destroyNotifySent) { + // '[mWin close]' causes a crash at exit. + // This probably happens b/c it sends events to the main loop + // but our resources are gone ?! + // However, issuing a simple release seems to work quite well. + // [mWin release]; + [mWin performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO]; + } - DBG_PRINT( "windowClose.X - %p,%d view %p,%d, parent %p\n", - mWin, getRetainCount(mWin), mView, getRetainCount(mView), pWin); + DBG_PRINT( "windowClose.X - %p,%d, released %d, view %p,%d, parent %p\n", + mWin, getRetainCount(mWin), !destroyNotifySent, mView, getRetainCount(mView), pWin); [pool release]; } |