Posted by
Sven Gothel on
Dec 03, 2011; 8:11am
URL: https://forum.jogamp.org/Discussion-Applet-s-GLProfile-s-initSingleton-shutdown-tp3556730.html
Allow me to formulate the latest JOGL lifecycle issues and changes,
helping to find a proper solution..
+++
Applet's & GLProfile's initSingleton(..) / shutdown(..)
https://jogamp.org/bugzilla/show_bug.cgi?id=505The reason of adding another lifecycle hook to GLProfile, 'shutdown(..)',
is to control the JVM/ClassLoader wider shared resources destruction (SharedResourceRunner).
The latter holds shared window/drawable/context used to query
available capabilities etc.
On the JOGL Test Applet page, the Applets call GLProfile.shutdown(..)
on the Applet's destroy() hook.
Of course, we should get rid of both explicit lifecycle hooks
to make the API more simple if possible.
GLProfile.initSingleton(..) could be removed already.
On Applet's I have experienced that 'sometimes' when you
stop an Applet (browser 'back' button for example),
the Applet related threads are just being killed.
Since the JVM is still running the shutdown hook is not being called yet
and the SharedResourceRunner is just killed.
In this case the JVM/ClassLoader wide data assumes the shared resources
are still valid.
Sadly this is not the case especially on Windows,
where the window handle becomes invalid if the creator thread dies.
If you press the browser 'forward' button again and the Applet
is about to start again, it would uses the shared resources,
assuming they are still valid. This is where the crash happend.
If we could catch the event where the Applet plugin container
kills our threads, we could properly release/mark the resources.
This would allow us to have the lifecycle managed w/o an API hook,
which is ofc more safe.
While writing this text, another way to handle this issue could
be to validate the whether the SharedResourceRunner thread is still valid
and act accordingly ..
I will run another test in this regard and may mark these lifecycle hooks
deprecated.
Ideas, suggestions and remarks are welcome.
~Sven