Safe execute external method using gl context

Hello,

at the moment i’m developing a simple jogl famework for my application
which has a java editor embedded.
The java code in my application can be compiled dynamically to a class.
In this class you can create a main method which makes the GL context available.

main(GL gl){

}
This main method then if it is compiled is called from the regular display method
inside the application and works fine so far.
The problem is that the display freezes if a failure occurs in the main method.
My question is how can i make the execution of the main method more stable to prevent that the 3d display freezes.

Any help or suggestion is appreciated

Try surrounding the call to main(gl) with a try…catch block in the display() call. That way if it causes any error in execution, you could just print the error out to a console instead of semi-crashing your program.

Can you please try to boil this down to the simplest test case possible? At this point it’s unclear what the problem might be.

If you aren’t manually calling GLContext.makeCurrent() and release(), then JOGL should be releasing the GLContext even if you throw an exception from your main(GL) method.

First of all thank you both for the fast reply.
I try to explain it more explicitly.

Inside my display method custom code is executed and then also the compiled code
with a timer. The custom code is still wrapped in a try-catch block
public void display(GLAutoDrawable drawable) {
gl = drawable.getGL();


if (custom != null) {
try {
custom.main(gl);
} catch (RuntimeException e) {

	 e.printStackTrace();
	}
}

}

If now an exception occurs in this method how can i avoid
a freezing of the application so that the embedded code
is executed and the timer isn’t stopped.
For example if i try to draw a 3d model (which is defective) in my main method
with the gl context .
Is there is an general advice to safely execute code
which is created for examply by another user which creates some custom code
with the gl context.

By the way the application does not crash. Only
the view freezes and the timer stops.

Run with Java 6 and when the application freezes use the jstack tool that ships with the JDK against the process ID of the hung process. If you can post the resulting thread dump we can see what’s going wrong. In general if you’re squelching the exceptions propagated out of your main() method then they shouldn’t affect subsequent frames’ drawing, unless possibly the OpenGL state is getting corrupted so badly that something like swapping the frame buffers isn’t working. You should also consider installing a DebugGL in your init() method; see the jogl-demos source code for examples of this.

Ok, thank you very much again for your reply!
I think i need some time to examine this and to
produce and track this behaviour again.

If it don’t minds you i have also another question regarding the execution
of a method inside the display method .

Since i 've also a setup method in the compiled class (for loading models etc.).
At the moment i trigger this setup method inside the display with a boolean.

[i]triggerSetup=false;// is triggered with a button to true


public void display(GLAutoDrawable drawable) {
gl = drawable.getGL();


if(triggerSetup==true){

setup(GL gl)// execute the setup code

triggerSetup=false;
}
}[/i]
This is running very well but i didn’t
find any information on the internet
if this is one reasonable approach to trigger
a setup method or any other adjustments.

Again any comment about this is always a
help.

Yes, it’s a reasonable approach. You could also queue up your key and mouse event objects and dispatch them inside your display method, when you have an OpenGL context available.

Thanks again for your fast reply.
Again this information is really useful for me

Have a nice sunday