[vtkusers] Animation

Denis Barbier bouzim at gmail.com
Sun Nov 16 16:44:47 EST 2008


On 2008/11/16 PsyVis wrote:
>
> I've put everything inside the edt and lo and behold it works, but now the
> stop button is not recognized and if I try and shut the window nothing
> responds.

Events are queued in the EDT and processed sequentially.  If you put
a long running task in the EDT, user interface looks frozen until this task
is finished, since no other event will be processed.  So what you describe
now looks "normal".  You know now that previous crashes most certainly
come from threading issues, and the solution is to take care of concurrency.
Your code was
     SwingUtilities.invokeLater(new Runnable() {
           @Override
           public void run() {
               rp.getRenWin().Modified();
               rp.getRenWin().Render();
           }
       });
Here, you push a Runnable into the EDT, rp variable is known when this
Runnable is created, so the compiler will add calls to Modified() and Render()
methods on rp.getRenWin(), and processing in the main thread continues.
But you do not know when this Runnable is going to be executed in the EDT,
maybe instantaneously or maybe in 10 seconds, and the main thread continues
its job, so it may modify rp before the Runnable has started.

The first solution is to replace invokeLater by invokeAndWait, then the main
thread waits for the Runnable to finish before continuing.  This is very simple,
but the main thread is blocked, so you will not have optimal performance.
If you need better performance, this is a much harder task, you will have to
learn about concurrency with Swing, see for instance
    http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

Denis



More information about the vtkusers mailing list