protected void executeOnGdx ( final Runnable runnable ) { final CountDownLatch latch = new CountDownLatch ( 1 ) ; final AtomicReference < Exception > exceptionAt = new AtomicReference < Exception > ( ) ; Gdx . app . postRunnable ( new Runnable ( ) { @ Override public void run ( ) { try { runnable . run ( ) ; } catch ( Exception e ) { exceptionAt . set ( e ) ; } finally { latch . countDown ( ) ; } } } ) ; try { latch . await ( ) ; final Exception e = exceptionAt . get ( ) ; if ( e != null ) { failed ( e ) ; } } catch ( InterruptedException e ) { failed ( e ) ; } }
Executes runnable on main GDX thread . This methods blocks until runnable has finished executing . Note that this runnable will also block main render thread .