diff options
author | Sven Gothel <[email protected]> | 2013-11-01 01:25:32 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-11-01 01:25:32 +0100 |
commit | 85878162940067b39b17c71878446dff0759040d (patch) | |
tree | e63bd4eb2a20f06fd306ba01c8e59e86a211c6db | |
parent | cc57413180edc4e5102f6729ccca6c4695d93e42 (diff) |
Bug 882 - Crash on OSX when closing NEWT window - Fix: Release NewtMacWindow manually in close0()
Release NewtMacWindow manually in close0()
- Mark [NewtMacWindow setReleasedWhenClosed: NO] in init0(..)
- Release NewtMacWindow manually in close0(..)
Check pointer args in close0(..)
-rw-r--r-- | make/scripts/tests.sh | 4 | ||||
-rw-r--r-- | src/newt/native/MacWindow.m | 28 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/newt/DemoCreateAndDisposeOnCloseNEWT.java | 140 |
3 files changed, 164 insertions, 8 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index b03f0fa68..641c3a906 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -327,7 +327,7 @@ function testawtswt() { # av demos # #testnoawt jogamp.opengl.openal.av.ALDummyUsage $* -testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $* +#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple $* # @@ -557,6 +557,8 @@ testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $* #testnoawt com.jogamp.opengl.test.junit.jogl.caps.TestBug605FlippedImageAWT $* #testawt com.jogamp.opengl.test.junit.jogl.glsl.TestShaderCompilationBug459AWT +testnoawt com.jogamp.opengl.test.junit.newt.DemoCreateAndDisposeOnCloseNEWT $* +#testawt com.jogamp.opengl.test.junit.newt.DemoCreateAndDisposeOnCloseNEWT $* #testawt com.jogamp.opengl.test.junit.newt.TestCloseNewtAWT #testawt com.jogamp.opengl.test.junit.newt.TestWindowClosingProtocol01AWT $* #testnoawt com.jogamp.opengl.test.junit.newt.TestWindowClosingProtocol02NEWT $* diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index f8988cf15..f0ed170f0 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -716,8 +716,15 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_initWindow0 rectWin = NSMakeRect(x, y, w, h); } - [myWindow setReleasedWhenClosed: YES]; // default + [myWindow setReleasedWhenClosed: NO]; // We control NSWindow destruction! [myWindow setPreservesContentDuringLiveResize: NO]; +NS_DURING + if ( [myWindow respondsToSelector:@selector(setRestorable:)] ) { + // Available >= 10.7 - Removes restauration 'feature', really close + [myWindow setRestorable: NO]; + } +NS_HANDLER +NS_ENDHANDLER NSObject* nsParentObj = (NSObject*) ((intptr_t) parent); NSWindow* parentWindow = NULL; @@ -857,8 +864,19 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_close0 { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NewtMacWindow* mWin = (NewtMacWindow*) ((intptr_t) window); + if( NULL == mWin ) { + DBG_PRINT( "windowClose.0 - NULL NEWT win - abort\n"); + return; + } + BOOL isNSWin = [mWin isKindOfClass:[NSWindow class]]; + BOOL isNewtWin = [mWin isKindOfClass:[NewtMacWindow class]]; + NSWindow *pWin = [mWin parentWindow]; + DBG_PRINT( "windowClose.0 - %p [isNSWindow %d, isNewtWin %d], parent %p\n", mWin, isNSWin, isNewtWin, pWin); + if( !isNewtWin ) { + DBG_PRINT( "windowClose.0 - Not a NEWT win - abort\n"); + return; + } NewtView* mView = (NewtView *)[mWin contentView]; - NSWindow* pWin = [mWin parentWindow]; BOOL destroyNotifySent, isNSView, isNewtView; if( NULL != mView ) { isNSView = [mView isKindOfClass:[NSView class]]; @@ -905,11 +923,7 @@ NS_ENDHANDLER DBG_PRINT( "windowClose.1 - %p view %p, parent %p\n", mWin, mView, pWin); - // 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 release]; - } + [mWin release]; DBG_PRINT( "windowClose.Xp\n"); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/DemoCreateAndDisposeOnCloseNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/DemoCreateAndDisposeOnCloseNEWT.java new file mode 100644 index 000000000..e82204fd0 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/DemoCreateAndDisposeOnCloseNEWT.java @@ -0,0 +1,140 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.newt; + +import javax.media.nativewindow.WindowClosingProtocol; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; + +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.util.Animator; + +/** + * Manual test case validating closing behavior. + * <p> + * Validates bugs: + * <ul> + * <li>Bug 882: Crash on OSX when closing NEWT window</li> + * </ul> + * </p> + * + */ +public class DemoCreateAndDisposeOnCloseNEWT { + public static void main(String[] args) { + int closeMode = 0; // 0 - none, 1 - window, animator, 2 - animator, window, 3 - System.exit + + for(int i=0; i<args.length; i++) { + if(args[i].equals("-close")) { + closeMode = MiscUtils.atoi(args[++i], closeMode); + } + } + System.err.println("Close Mode: "+closeMode); + + final GLCapabilities caps = new GLCapabilities(GLProfile.getMaxProgrammable(true)); + caps.setBackgroundOpaque(true); + caps.setDoubleBuffered(true); + caps.setDepthBits(16); + final Animator animator = new Animator(); + GLWindow glWindow = GLWindow.create(caps); + animator.add(glWindow); + glWindow.addGLEventListener(new GLEventListener() { + @Override + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + System.out.println("GLEventListener.reshape"); + } + + @Override + public void init(GLAutoDrawable drawable) { + System.out.println("GLEventListener.init"); + } + + @Override + public void dispose(GLAutoDrawable drawable) { + System.out.println("GLEventListener.dispose"); + } + + @Override + public void display(GLAutoDrawable drawable) { + } + }); + glWindow.setTitle("Test"); + glWindow.setSize(1024, 768); + glWindow.setUndecorated(false); + glWindow.setPointerVisible(true); + glWindow.setVisible(true); + glWindow.setFullscreen(false); + glWindow.setDefaultCloseOperation(WindowClosingProtocol.WindowClosingMode.DISPOSE_ON_CLOSE); + glWindow.addWindowListener(new WindowAdapter() { + @Override + public void windowDestroyNotify(WindowEvent e) { + System.out.println("GLWindow.destroyNotify"); + } + + @Override + public void windowDestroyed(WindowEvent e) { + System.out.println("GLWindow.destroyed"); + animator.stop(); + } + }); + + animator.start(); + + switch( closeMode ) { + case 1: + sleep1s(); + glWindow.destroy(); + sleep1s(); + animator.stop(); + break; + case 2: + sleep1s(); + animator.stop(); + sleep1s(); + glWindow.destroy(); + break; + case 3: + sleep1s(); + System.exit(0); + break; + default: break; // 0 - nop + } + } + static void sleep1s() { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + +} |