Text Mesh Pro UGUI invisible - does not generate mesh for text and throws exception

I’m having some trouble with TextMeshProUGUI not rendering any text meshes in the scene after I change the text string via code in play mode. When this happens, the text shows correctly in the inspector, but does not show in the scene view:

When the SceneView is set to wireframe, it looks the same, no meshes are generated. The issue may happen silently, without any errors, but sometimes I also see an exception logged to the console:

NullReferenceException: Object reference not set to an instance of an object
TMPro.TextMeshProUGUI.GenerateTextMesh () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMPro_UGUI_Private.cs:2094)
TMPro.TextMeshProUGUI.GenerateTextMesh () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMPro_UGUI_Private.cs:2791)
TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMPro_UGUI_Private.cs:1656)
TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TextMeshProUGUI.cs:209)
UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/Program Files/Unity/Hub/Editor/2019.2.17f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/CanvasUpdateRegistry.cs:198)
UnityEngine.Canvas:SendWillRenderCanvases() (at C:/buildslave/unity/build/Modules/UI/ScriptBindings/UICanvas.bindings.cs:72)

In the TMP source code it looks as if the components material reference is null, however, the font and material are all correctly assigned.

Any idea what could be going wrong here and how I can narrow this down? I’m currently trying to reproduce a case in a clean scene, but it only seems to happen for specific text strings at specific times in the game.

Does the text string that exhibits the issue include characters that are not present in the primary font asset?

No, in other circumstances, the same text shows correctly, e.g. in the editor. After some more investigation I found that the issue occurs for a text that includes sprite icons from a TMP Sprite Asset. The glyph themselves work fine in general, but I still see this exception in specific cases. Before setting the text at runtime I also set the font, so that might trigger some sort of additional rebuild, I’m thinking, which causes the exception in the same frame.

If I simple insert a null check into the TMP source code line, everything seems to work correctly. At least there are no exceptions and the text appears on screen again. But this probably only hides the real issue.

Please see if you get the same results using the latest preview release of TMP.

Be sure to test on a backup of the project has there have been many changes since version 2.0.1 to version 2.1.0-preview.3.