TextRenderer crash the JVM after removing then adding a canvas from a AWT or Swing layout

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

TextRenderer crash the JVM after removing then adding a canvas from a AWT or Swing layout

Martin
Hi,



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
- init()
- display()
- 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

Stack: [0x0000000172d10000,0x0000000172f13000],  sp=0x0000000172f10040,  free space=2048k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [GLEngine+0x12a8fc]  gleRunVertexSubmitImmediate+0x1814
C  [GLEngine+0x21d74]  glDrawArrays_Exec+0x268
C  [libjogl_desktop.dylib+0x238e8]  Java_jogamp_opengl_gl4_GL4bcImpl_dispatch_1glDrawArrays1__IIIJ+0x40
j  jogamp.opengl.gl4.GL4bcImpl.dispatch_glDrawArrays1(IIIJ)V+0
j  jogamp.opengl.gl4.GL4bcImpl.glDrawArrays(III)V+45
J 1629 C1 com.jogamp.opengl.util.awt.TextRenderer$Pipelined_QuadRenderer.drawVertexArrays()V (236 bytes) @ 0x00000001059b236c [0x00000001059b1600+0xd6c]
J 1663 C1 com.jogamp.opengl.util.awt.TextRenderer.flushGlyphPipeline()V (15 bytes) @ 0x00000001059ca04c [0x00000001059c9e80+0x1cc]
j  com.jogamp.opengl.util.awt.TextRenderer.endRendering(Z)V+1
j  com.jogamp.opengl.util.awt.TextRenderer.endRendering()V+2
j  org.jzy3d.painters.NativeDesktopPainter.drawText(Lorg/jzy3d/painters/Font;Ljava/lang/String;Lorg/jzy3d/maths/Coord3d;Lorg/jzy3d/colors/Color;F)V+215

Reading more in detail the code of TextRenderer shows that the crash happens here.

I presume the GL context is somehow reset and that we lost the vertex/texture buffers.

I tried using the immediate mode with TextRenderer.setUseVertexArrays(false).

It avoids the crash, but the text is replaced by black pixels as shown below.

Does anyone see a way to fix this?

 

 
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer crash the JVM after removing then adding a canvas from a AWT or Swing layout

Martin
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.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer crash the JVM after removing then adding a canvas from a AWT or Swing layout

gouessej
Administrator
Why not creating the text renderer only in GLEventListener.init() instead?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer crash the JVM after removing then adding a canvas from a AWT or Swing layout

Martin
Good idea :) Or invoking the deletion of the TextRenderer instance in GLEventListener.dispose() so that the cache can still work a bit.

Thank you Julien for your suggestion.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer crash the JVM after removing then adding a canvas from a AWT or Swing layout

Martin
I confirm this solved the problem, thank Julien.

In addition I tested the pending MR about TextRenderer you pointed me to some time ago and it is working great!

I extracted this MR in a separate project since it has never been merged : https://github.com/jzy3d/jogl-text-renderer

Anyone can use it, the only point is that it loads before the existing text renderer on my configuration, but it may happen differently for others. The text renderer in this module has the exact same name than the existing one.

Also reported here.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer crash the JVM after removing then adding a canvas from a AWT or Swing layout

gouessej
Administrator
Great job Martin. Andy Brown's contribution is really good, thank you for reusing his stuff. I hope that we're going somewhere with JogAmp...
Julien Gouesse | Personal blog | Website