NASAWorldWind / WorldWindJava

The NASA WorldWind Java SDK (WWJ) is for building cross-platform 3D geospatial desktop applications in Java.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Text becomes corrupted over time

cwfry-ca opened this issue · comments

Description

After many hours or days of Worldwind running, characters in a font may be incorrectly drawn. See the capital "R" below for an example.
garbled2

The TextRenderer class employs a JOGL RectanglePacker in order to manage the layout of font glyphs on a texture. The RectanglePacker includes a feature where it will reposition ‘rectangles’ (glyphs) in order to de-fragment the space and make room for new rectangles. The RectanglePacker only does this when reaching the limit of rectangles that can be packed into its managed space.
Once the RectanglePacker decides to ‘compact’ its rectangles, it notifies the TextRenderer via the TextRenderer.Manager inner class. Currently, the Manager responds by updating the font’s texture, but it does not update any Objects that hold coordinates for that texture. When these stale references are used in subsequent draws, the old location of the font glyph is used and garbled text is painted to the screen. I believe that TextRenderer.Glyph#glyphRectForTextureMapping holds the reference that is causing the problem.

Steps to Reproduce

  1. Draw a large number of different text glyphs to the screen in order to load the RectanglePacker near to the point where it will attempt to compact / de-fragment the rectangles. It helps to use a large font, and to use the TextRenderer.DebugListener to see the whole texture.
  2. Stop drawing a small subset of the glyphs, in order to evict them from the cache and free up ‘fragmented’ space in the texture.
  3. Add more, distinct glyphs in order to trigger the compacting behaviour

Expected behavior: All glyphs are drawn to the screen using the new texture coordinates generated during the ‘compact’ operation.

Actual behavior: Glyphs which were moved by compacting are drawn using stale coordinates. The area designated by the stale coordinates is likely not aligned with any glyph and so bits and pieces of other glyphs are drawn to the screen.

Reproduces how often: Infrequently. Typically occurs only when using a large font that changes relatively often, causing the texture cache to be fragmented and eventually compacted.

Operating System and Version

RHEL 7 and WorldWind 2.1.0. JOGL 2.1.5

Additional Information

Can perhaps be quick-fixed by changing TextRenderer.Manager#canCompact() to return false instead of true.