Created
April 24, 2014 19:25
-
-
Save stacktracer/11266465 to your computer and use it in GitHub Desktop.
Trigger deadlock in waitForVisible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main( String[] args ) throws Exception | |
{ | |
GLAutoDrawable contextOwner = GLUtils.newOffscreenDrawable( GLProfile.GL2GL3 ); | |
GLContext context = contextOwner.getContext( ); | |
final JTabbedPane tabbedPane = new JTabbedPane( ); | |
JFrame frame = FrameUtils.newFrame( "AWT Deadlock Example", tabbedPane, JFrame.EXIT_ON_CLOSE ); | |
FrameUtils.showFrameCentered( frame ); | |
for ( int i = 0; i < 100; i++) | |
{ | |
final String tabName = "" + i; | |
final NewtSwingGlimpseCanvas canvas = new NewtSwingGlimpseCanvas( context ); | |
Plot2D plot = new Plot2D( "" ); | |
plot.getLayoutCenter( ).addPainter( new BackgroundPainter( ) ); | |
plot.getLayoutCenter( ).addPainter( new GridPainter( ) ); | |
plot.getLayoutCenter( ).addPainter( new GlimpseDataPainter2D( ) | |
{ | |
public void paintTo( GL2 gl, GlimpseBounds bounds, Axis2D axis ) | |
{ | |
// This runs in canvas's animator thread | |
// At this point, the animator thread holds the GlimpseLayout lock | |
// getScreenResolution() involves grabbing the AWT lock | |
// | |
Toolkit.getDefaultToolkit( ).getScreenResolution( ); | |
} | |
} ); | |
plot.getLayoutCenter( ).addPainter( new BorderPainter( ) ); | |
canvas.addLayout( plot ); | |
GLUtils.startFpsAnimator( 1000, canvas ); | |
SwingUtilities.invokeAndWait( new Runnable( ) | |
{ | |
public void run( ) | |
{ | |
// This causes the JOGL event thread to wait for canvas's peer to become visible | |
// While it's waiting, the event thread holds the AWT lock | |
// Also while waiting, the event thread occasionally wakes up to dispatch input events | |
// If it has to dispatch a mouse event, Glimpse tries to figure out which layout the mouse is in | |
// That involves grabbing the GlimpseLayout lock | |
// | |
// So ... if you move your mouse around on an existing canvas while | |
// a new canvas is being made visible, it can deadlock | |
// | |
tabbedPane.add( tabName, canvas ); | |
} | |
} ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment