TextRenderer crash the JVM after removing then adding a canvas from a AWT or Swing layout
My use case involves removing and then adding back a GLCanvas (or GLJPanel) to an AWT (or Swing) layout. When doing such sequence of add/remove/add a component, the GLEventListener will have its method invoked in this order
- dispose() (while removing the canvas)
- init() (again due to the component being added again)
Everything is handled cleanly in JOGL, except in the "legacy" TextRenderer (which usually does a great job). Indeed, when running the test mentionned above, I got a JVM crash
Re: TextRenderer crash the JVM after removing then adding a canvas from a AWT or Swing layout
This post was updated on .
Digging a bit more in TextRenderer shows that the problem comes from the fact that TextRenderer build a cache of the strings that were previously rendered in textures. The textures were most probably deleted after the call to GLEventListener.dispose().
It is not possible to add a cache invalidation method to the TextRenderer by overriding because the stringLocations is private.
It is however possible to avoid building cache by creating a new TextRenderer for each string to draw, as shown here.
Sad, but performance remains OK for me with small charts.
I dropped a ticket here to think about adding this cache invalidation method.