QText2DEntity: fix QTextureAtlas parenting that could lead to crashes


We rely on a DistanceFieldFont object to manage QTextureAtlas that hold
the glyphs. The DistanceFieldFont/QTextureAtlas are supposed to be parented
by the scene root to ensure that a QTextureAtlas lives as long as possible.

DistanceFieldFont/QTextureAtlas are stored in a cache global to the scene
to minimize the use of resources.

When adding text elements, we can reuse atlases since the cache is global to
the scene and only destroy an atlas (and remove it from the cache) when we
know no more glyphs are referencing it.

However we were mistakenly passing a null parenty to DistanceFieldFont instace
of the scene root. This resulted on the QTextureAtlas not being parented by
the scene root but rather by the first DistanceFieldRenderer to use the atlas.
This meants that if the DistanceFieldRenderer were to be destroyed, so would
the atlas (yet it would still be referenced by the glyph cache leading to
crashes).

Pick-to: 6.5 6.4 6.2 5.15
Change-Id: Id84f6a651b162a4bb3c571b11388fd2429b231de
Reviewed-by: Mike Krus <mike.krus@kdab.com>
commitb1a135c547f38db0b2ce6b7bc4c4cccc43ef87d3
parent92b9c37731e9cdea13e075728bbfbb3f0e59ce6a
authorPaul Lemire <paul.lemire@kdab.com>
committerPaul Lemire <paul.lemire@kdab.com>
commit timeFri, 10 Feb 2023 15:24:54 +0000