Infinite loop hanging app when working with threads

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Infinite loop hanging app when working with threads

Alberto Martins
I am facing a issue using Newts GLWindow painting to FBO.

To help validate the issue I made a simple application to reproduce the problem:

public static GLWindow window;
public static Animator animator;
   
    public static void main( String[] args )
    {
//        ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
//        pool.execute(new WorkerThread());
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);
        caps.setBackgroundOpaque(false);
        caps.setOnscreen(false);

        window = GLWindow.create(caps);
        animator = new Animator(window);

        //Size is purposely big to make exception be thrown
        window.setSize(40000, 40000);
        window.setVisible(true);
       
        System.out.println("TEST2");
    }

If I execute this simple code in the main Thread, the exception is thrown as expected.
However, if I run the same code inside a thread (uncomment the first two lines of the main, creating a WorkerThread class with the same code), the application enters an infinite loop in the jogamp.newt.DefaultEDTUtil class, precisely in the line 347 of the run() method.

Is this a bug in the API implementation, or is there a way to force this thread to exit?

Regards,
Alberto Martins
Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop hanging app when working with threads

elect
Hi Alberto,

what's at that line?
Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop hanging app when working with threads

Alberto Martins
Hi, the line it's stuck is:

if(!shouldStop) {
                        dispatchMessages.run();
                    }

This is inside a do ... while(!shouldStop).

I ended up resolving my issue by placing a try catch block around the window.setVisible(true) call and forcibly calling window.destroy on the catch block(if i don't destroy the window the app still enters the infinite loop).

Still think there is something weird going on with the API and this is not exactly the cleanest way out but for now it works! :)

Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop hanging app when working with threads

gouessej
Administrator
Please can you post your code so that there is no ambiguity on what you're doing?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop hanging app when working with threads

Alberto Martins
Hi,

Sorry for delay, been kinda busy these days.

I can't share the code due to NDA, but I've put together a simple maven project to reproduce the issue on bitbucket

https://bitbucket.org/alberto_antunes/jogamp-issue

For now, my problem is solved with the window.destroy workaround but I'm very interested in knowing if there is a cleaner solution to that.
Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop hanging app when working with threads

jmaasing
In AWT, Swing and JavaFX creating any kind of GUI component (windows et c) on any other thread than the Swing EDT will lead to bad/undefined behavior. So it would be pure luck if your test code would work with those frameworks.
I guess that NEWT have the same kind of design with a special thread (both for event dispatching and also because only one thread can 'own' OpenGL at a time). If so then undefined behavior (including stuck threads) is to be expected.