Bug 761

Summary: Crash during X11 shutdown using AMD fglrx driver
Product: [JogAmp] Newt Reporter: Xerxes Rånby <xerxes>
Component: x11Assignee: Sven Gothel <sgothel>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: ---    
Version: 1   
Hardware: pc_x86_32   
OS: linux   
Type: --- SCM Refs:
jogl 41c626d8a27981e694b3b728a9a2f2bc8def939d jogl 2d32b056c7b1b6b3d071d79fb4c2d4e9113b59d5
Workaround: ---

Description Xerxes Rånby 2013-06-21 14:36:35 CEST
Ubuntu 12.04 32bit
The crash is found to trigger in about 1/4 runs during unclean shutdown triggered by catching an ALException inside the GLEventListener display
For more information see: http://jogamp.org/log/irc/jogamp_20130621050527.html

GL Profile     GLProfile[GL3bc/GL3bc.hw]
GL Version     3.3 (hardware) - 3.3.11627 Compatibility Profile Context [GL 3.3.0, vendor 0.0.0 (n/a)]
Quirks         [DontCloseX11Display]
Impl. class    jogamp.opengl.gl4.GL4bcImpl
GL_VENDOR      ATI Technologies Inc.
GL_RENDERER    ATI Radeon HD 4800 Series
GL_VERSION     3.3.11627 Compatibility Profile Context
GLSL           true, has-compiler-func: true, version: 3.30 / 3.30.0
GL_EXTENSIONS  196

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x730ffb40 (LWP 2614)]
0x736c5334 in _XEventsQueued (dpy=0x6fbed858, mode=2) at ../../src/xcb_io.c:350
350	../../src/xcb_io.c: Filen eller katalogen finns inte.
(gdb) bt
#0  0x736c5334 in _XEventsQueued (dpy=0x6fbed858, mode=2)
    at ../../src/xcb_io.c:350
#1  0x736b60a8 in XEventsQueued (dpy=0x6fbed858, mode=2)
    at ../../src/Pending.c:43
#2  0x6cac126b in Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0
    ()
   from /tmp/jogamp_0000/file_cache/jln137143273701419511/jln3716836924835917257/libnewt.so
#3  0xb3e0a64a in ?? ()
...

Stack: [0x730af000,0x73100000],  sp=0x730feb50,  free space=318k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libX11.so.6+0x37334]  _XEventsQueued+0x24

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  jogamp.newt.driver.x11.DisplayDriver.DispatchMessages0(JJJ)V+0
j  jogamp.newt.driver.x11.DisplayDriver.dispatchMessagesNative()V+84
j  jogamp.newt.DisplayImpl.dispatchMessages()V+112
j  jogamp.newt.DisplayImpl$3.run()V+4
j  jogamp.newt.DefaultEDTUtil$EventDispatchThread.run()V+61
v  ~StubRoutines::call_stub
Comment 1 Xerxes Rånby 2013-06-21 14:54:14 CEST
Workaround: shutdown using fglrx looks to behave well after removing closePendingDisplayConnections(); from X11Util

diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java b/src
index 2d9c42e..2c69cb8 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
@@ -212,7 +212,7 @@ public class X11Util implements ToolkitProperties {
                         // dislike closing of X11 Display's (w/ ATI driver). 
                         if( isJVMShuttingDown ) {
                             isInit = false;                            
-                            closePendingDisplayConnections();    
+                            //closePendingDisplayConnections();    
                             openDisplayList.clear();
                             reusableDisplayList.clear();
                             pendingDisplayList.clear();
Comment 2 Sven Gothel 2013-06-23 01:24:57 CEST
Excellent - I was almost disregarding the fglrx issue.
Best thing, this leads to a proper JVM shutdown sequence and dependency.

+++

Move GLDrawableFactory.shutdownHook -> NativeWindowFactory.shutdownHook, the latter handles 
customShutdownHooks for NativeWindow, JOGL and NEWT.
    
  Unifying our shutdown mechanism is required to provide a controlled shutdown sequence.
  NativeWindowFactory is chosen to be the new central entry point, 
  since it is the lowest denominator (common module).
    
    - Move GLDrawableFactory.shutdownHook -> NativeWindowFactory.shutdownHook
      Reverse the shutdown dependency for clarity and availability to all modules,
      i.e. NEWT may not know about JOGL.
    
      Remove the 'gamma' shutdown hook,
      instead simply call GLDrawableFactoryImpl.resetDisplayGamma() before destroy.
    
  NativeWindowFactory.shutdownHook handles customShutdownHooks for NativeWindow, JOGL and NEWT
      - Modules can register their shutdown runnable at head or tail of list.
      - Allows controlled shutdown across all modules.

NEWT registers one customShutdownHook @  NativeWindowFactory.shutdownHook head, 
allowing proper resource cleanup.
    
    1 WindowImpl.shutdownAll():
      - For all instances:
        - mark invalid (causes any user thread to disregard the window)
    
    2 ScreenImpl.shutdownAll():
      - Removed own shutdown-hook!
      - For all instances:
        - Reset ScreenMonitorState
    
    3 DisplayImpl.shutdownAll():
      - For all instances:
        - Remove EDT
        - closeNativeImpl
    
  Manually tested on X11 w/ NV and ATI Catalyst (fglrx)
      - DFLAGS="-Djogl.debug.GLDrawable -Dnativewindow.debug.X11Util -Dnativewindow.debug.NativeWindow -Dnewt.debug.Display -Dnewt.debug.Screen -Dnewt.debug.Window"
      - java $DFLAGS com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT -time 2000 -sysExit testExit
      - valid arguments for sysExit: testExit, testError, displayExit, displayError