We are experiencing a crash on iOS when a gameObject that has a TextMeshPro component is enabled.
We don't have this issue on Editor nor Android builds.
The stack shows recursive calls to GenerateTextMesh()
on TextMeshPro
component.
Stack;
After debugging the code inside the plugin we realized that recursive calls are executed when some rendering conditions are met, causing TextMeshPro to make some adjustments and then retry the rendering process. (For example, if the text is doesn't fit the area it will try to adjust the size if 'best fit' is enabled. Or it will trunk part of the text. This depends on the selected settings on the component).
In our case, all those successive calls to GenerateTextMesh()
were generated in an attempt to fit the text inside the desired box (the yellow contour that TextMeshPro draws on the component).
Our gameObject looked like this;
TextMeshPro component includes a RectTransform and you can define the 'size' of the component there. This feels a little bit odd since a RecTransform is a UI component and we are in the render world.
Looking at the component more carefully we discovered that the size on the RectTransform
was too big (around 20x5) but the area that we needed to fill was around 3x1. And in order to fit the text inside the desired area, there was a heavy use on the Margin
setting on Advanced Settings
; so the component size was around 20, the sum of the margins was around 17.
After discovering this forced way to make it fit, we changed the values to something more 'natural' hoping to cut some recursive calls on GenerateTextMesh()
.
Once the updates were made, the RectTransform component looked like this;
And the margins were set all to zero;
And after these changes, the crash was solved!
ps; I am auto answering this question after hours of repeating the process of debugging and building, hoping to save some time to any other person :D