TextMeshPro NullReferenceException on scene reload

Hi,
about 50% of the time when I reload my scene by simply doing ```
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);


[Exception] NullReferenceException: Object reference not set to an instance of an object
TextMeshProUGUI.UpdateSDFScale() Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMPro_UGUI_Private.cs:4264

TextMeshProUGUI.InternalUpdate() Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMPro_UGUI_Private.cs:1582

TMP_UpdateManager.DoRebuilds() Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_UpdateManager.cs:169

TMP_UpdateManager.OnBeginFrameRendering() Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_UpdateManager.cs:144

RenderPipelineManager.BeginFrameRendering() :0

RenderPipeline.BeginFrameRendering() :0

HDRenderPipeline.Render() Library/PackageCache/com.unity.render-pipelines.high-definition@7.1.8/Runtime/RenderPipeline/HDRenderPipeline.cs:1127

RenderPipeline.InternalRender() :0

RenderPipelineManager.DoRenderLoop_Internal() :0


I am running Unity 2019.3.0f6 with the TextMesh Pro 2.0.1 (2019.3 Verified) package.
Has anyone else encountered this issue?

Thanks!

- Fred

Please test with the latest release which is 2.1.0-preview.4 for Unity 2019.x.

If the issue persists, it is likely HDRP and timing related. The easiest way for me to take a look at that would be for you to submit a bug report with the included project which would allow me to easily reproduce the behavior to figure out what is going on.

1 Like

Hi Stephan,

I exactly the same issue. My game is today #1 worldwide on Android and iOS.

It happens about 500K times today…!

Is it real crash or just an error message?

We can’t reproduce it on our side.

Merci!

Did you recently upgrade TMP or Unity or is this something g that just started happening?

Does it happen on both platforms or is it specific to one platform?

Are you able to reproduce the behavior on your end?

So I updated TMP package to 2.1.0-preview.4 for Unity 2019.x and when I intereact with UI objects while playing the game after a bit, I will get this error spammed when I move my mouse and I can’t interact with the game at all. I’m reverting to the latest non-preview version for now since this is worse than the previous error I was getting (which happens sometimes but regularly).

MissingReferenceException: The object of type 'CanvasRenderer' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.UI.GraphicRaycaster.Raycast (UnityEngine.Canvas canvas, UnityEngine.Camera eventCamera, UnityEngine.Vector2 pointerPosition, System.Collections.Generic.IList`1[T] foundGraphics, System.Collections.Generic.List`1[T] results) (at /Applications/Unity/Hub/Editor/2019.3.0f6/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/GraphicRaycaster.cs:321)
UnityEngine.UI.GraphicRaycaster.Raycast (UnityEngine.EventSystems.PointerEventData eventData, System.Collections.Generic.List`1[T] resultAppendList) (at /Applications/Unity/Hub/Editor/2019.3.0f6/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/GraphicRaycaster.cs:225)
UnityEngine.EventSystems.EventSystem.RaycastAll (UnityEngine.EventSystems.PointerEventData eventData, System.Collections.Generic.List`1[T] raycastResults) (at /Applications/Unity/Hub/Editor/2019.3.0f6/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:255)
UnityEngine.EventSystems.PointerInputModule.GetMousePointerEventData (System.Int32 id) (at /Applications/Unity/Hub/Editor/2019.3.0f6/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/InputModules/PointerInputModule.cs:277)
UnityEngine.EventSystems.StandaloneInputModule.ProcessMouseEvent (System.Int32 id) (at /Applications/Unity/Hub/Editor/2019.3.0f6/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/InputModules/StandaloneInputModule.cs:546)
UnityEngine.EventSystems.StandaloneInputModule.ProcessMouseEvent () (at /Applications/Unity/Hub/Editor/2019.3.0f6/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/InputModules/StandaloneInputModule.cs:532)
UnityEngine.EventSystems.StandaloneInputModule.Process () (at /Applications/Unity/Hub/Editor/2019.3.0f6/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/InputModules/StandaloneInputModule.cs:289)
UnityEngine.EventSystems.EventSystem.Update () (at /Applications/Unity/Hub/Editor/2019.3.0f6/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

The above error does not appear to be related to the TMP package but to the event system and ugui.

Did you also happen to upgrade to a newer version of Unity?

No the only thing I changed was updating the TMP package and reverting that change fixed the issue. When debugging, the faulty graphic (that is null and throwing the exception) is never from the same object but it is always a TMP mesh

I would like to take a look at the scene / figure out a way to reproduce this issue as everything in the above log references the ugui package / event system.

Can you submit a bug report with the included project and reproduction steps?

We’re also having the “‘CanvasRenderer’ has been destroyed” error since 2.1.0-preview.4.
I reported the bug with a minimal project as case 1225093.
While testing it I got it down to the following steps:

  • The text needs to be in a nested canvas (at least two)
  • The font has to have a fallback font and the text must make use of it.
  • The text needs to be destroyed

Revise the OnDisable() function in the TMP_SubMeshUI.cs script as follows:

protected override void OnDisable()
{
    //Debug.Log("*** SubObject OnDisable() ***");
    base.OnDisable();

    if (m_MaskMaterial != null)
    {
        TMP_MaterialManager.ReleaseStencilMaterial(m_MaskMaterial);
        m_MaskMaterial = null;
    }

    if (m_fallbackMaterial != null)
    {
        TMP_MaterialManager.ReleaseFallbackMaterial(m_fallbackMaterial);
        m_fallbackMaterial = null;
    }
}

Thank you! This seems to fix it :slight_smile:

1 Like