Search Unity

TMP nullreference in build

Discussion in 'UGUI & TextMesh Pro' started by TJHeuvel-net, Jan 29, 2018.

  1. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    We're running into a myriad of nullreferences in TextMeshPro, but only in a build. I've checked and made sure all fonts and materials are in the resources folder, but otherwise i'm not quite sure how to debug this issue. I've seen some corrupt SubTextObjects before, they would remain visible in the prefab in editor time. But those are all deleted.

    It only happens in a build, which uses assetbundles. In editor with assetbundles the issue does not occur. The UI is being spawned from a prefab, but there are no issues there (its all visible). It doesnt occur with all text, and it all still seems to be properly rendered.

    We're building with Unity 2017.1.2, currently waiting on a few issues to be fixed before we can update to 2017.3.

    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3.   at TMPro.TMP_SubMeshUI.UpdateMaterial () [0x00000] in <filename unknown>:0
    4.   at TMPro.TMP_SubMeshUI.SetMaterialDirty () [0x00000] in <filename unknown>:0
    5.   at TMPro.TMP_SubMeshUI.RecalculateMasking () [0x00000] in <filename unknown>:0
    6.   at TMPro.TMP_SubMeshUI.OnEnable () [0x00000] in <filename unknown>:0
    7. UnityEngine.GameObject:Internal_AddComponentWithType(Type)
    8. UnityEngine.GameObject:AddComponent(Type)
    9. UnityEngine.GameObject:AddComponent()
    10. TMPro.TMP_SubMeshUI:AddSubTextObject(TextMeshProUGUI, MaterialReference)
    11. TMPro.TextMeshProUGUI:SetArraySizes(Int32[])
    12. TMPro.TMP_Text:parseInputText()
    13. TMPro.TextMeshProUGUI:OnPreRenderCanvas()
    14. TMPro.TextMeshProUGUI:Rebuild(CanvasUpdate)
    15. UnityEngine.UI.CanvasUpdateRegistry:performUpdate()
    16. UnityEngine.Canvas:SendWillRenderCanvases()
    17.  
    18.  
    19. NullReferenceException: Object reference not set to an instance of an object
    20.   at TMPro.TMP_SubMeshUI.UpdateMaterial () [0x00000] in <filename unknown>:0
    21.   at TMPro.TMP_SubMeshUI.SetMaterialDirty () [0x00000] in <filename unknown>:0
    22.   at UnityEngine.UI.MaskableGraphic.OnCanvasHierarchyChanged () [0x00000] in <filename unknown>:0
    23. UnityEngine.Object:Destroy(Object, Single)
    24. UnityEngine.Object:Destroy(Object)
    25. LoadingScreenManager:CloseMenu()
    26. LoadingScreenBase:doneLoading()
    27. LoadingScreenBase:Update()
    28.  
    29. NullReferenceException: Object reference not set to an instance of an object
    30.   at TMPro.TMP_SubMeshUI.UpdateMaterial () [0x00000] in <filename unknown>:0
    31.   at TMPro.TMP_SubMeshUI.SetMaterialDirty () [0x00000] in <filename unknown>:0
    32.   at UnityEngine.UI.MaskableGraphic.OnDisable () [0x00000] in <filename unknown>:0
    33.   at TMPro.TMP_SubMeshUI.OnDisable () [0x00000] in <filename unknown>:0
    34.  
     
    Last edited: Jan 29, 2018
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Most likely the Asset Bundles are losing their reference to either the material, font atlas texture and possibly shader.

    When the bundle is loaded, make sure these resources are assigned properly to the font asset.
     
  3. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    We keep running into this issue, even when we dont use assetbundles at all.

    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3.   at TMPro.TMP_SubMeshUI.UpdateMaterial () [0x00000] in <filename unknown>:0
    4.   at TMPro.TMP_SubMeshUI.SetMaterialDirty () [0x00000] in <filename unknown>:0
    5.   at UnityEngine.UI.MaskableGraphic.OnDisable () [0x0000f] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\UI\Core\MaskableGraphic.cs:133
    6.   at TMPro.TMP_SubMeshUI.OnDisable () [0x00000] in <filename unknown>:0
    7.  
    We were spying into the DLL for a bit, maybe its the fact that components are added/getted in an OnDisable?
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Are you able to reliably reproduce this? If so please submit a bug report with the case #.
     
  5. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
  6. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Alright, we've finally found the issue. And it's totally unrelated to TextMeshPro, and completely our fault.

    We are very performance conscious, and therefore we modified the UnityEngine DLL to skip RequireComponents checks. This sped up Destroying objects massively (500ms per player dying), and didnt cause any issues at that moment. However the TMP_SubMeshUI correctly relies on RequireComponent to add this CanvasRenderer.

    Apologies!
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    No apologies necessary. Glad you have identified the source of the behavior :)