TMP_InputField GenerateCaret m_TextComponent.canvas exception

Hello

Could I request clarification or modification?

I have a setup that I can’t quite get to the bottom of a problem. I have a gameobject with a canvas and two input fields. Part of a larger project but those are the elements that cause me the issue.

I set the gameobject as inactive, but I till occasionally get the following error

    (Filename: currently not available on il2cpp Line: -1)
2020-07-27 16:59:10.266 23066-23081/xxx.xxxx.xxxt E/Unity: NullReferenceException: Object reference not set to an instance of an object.
      at TMPro.TMP_InputField.GenerateCaret (UnityEngine.UI.VertexHelper vbo, UnityEngine.Vector2 roundingOffset) [0x00000] in <00000000000000000000000000000000>:0
      at TMPro.TMP_InputField.OnFillVBO (UnityEngine.Mesh vbo) [0x00000] in <00000000000000000000000000000000>:0
      at TMPro.TMP_InputField.UpdateGeometry () [0x00000] in <00000000000000000000000000000000>:0
      at TMPro.TMP_InputField.Rebuild (UnityEngine.UI.CanvasUpdate update) [0x00000] in <00000000000000000000000000000000>:0
      at UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () [0x00000] in <00000000000000000000000000000000>:0
      at UnityEngine.Canvas+WillRenderCanvases.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    UnityEngine.UI.CanvasUpdateRegistry:PerformUpdate()
    UnityEngine.WillRenderCanvases:Invoke()

I can get rid of the exception by adding the following to the top of GenerateCaret

if (m_CaretVisible == false || m_TextComponent.canvas == null)
                return;

Once the error starts it won’t stop and then causes a performance issue on the Android-based VR device.

Even if I mark the canvas as not enabled I still get the issue. Unity seems to still want to Render the Canvas even though it is not enabled.

It is however excruciatingly difficult to pin down the exact cause. I want to think its a timing issue in terms of when the canvas is marked as not enabled.

Has anyone come across something similar and if not could I request that a check for m_TextComponent.canvas == null be a permanent addition to GenerateCaret.

For whatever reason, when a Canvas is disabled, the “canvas” property is set to null in the UI framework. As such, all these references to the Canvas end up null which is an issue. Ideally, a disabled canvas should be just disabled where given it is not actually null, the references should be maintained.

Having said that, please use the most recent release of the TMP package and let me know if the behavior persists.

The latest for Unity 2018.4 is version 1.5.1. Version 2.1.1 for Unity 2019.x and version 3.0.1 for Unity 2020.x.

Independently of that, I will verify the current handling of this case of the Canvas being null when it is disabled and make the necessary changes.

Thanks for the reply. I am using 1.5.1 on Unity 2018.4.25f1. Plan is to move to later releases after next major release.

I made the suggested change which will be in the next release of the TMP package.

Hi @Stephan_B
I’m running into the same issue, I’m on Unity 2019.3.12f1. And I’m on TMPro 2.0.1. I can look into upgrading but to be honest I don’t understand what’s in preview and what’s not. When I open package manager, it looks as if Ii’m up to date with 2.0.1. However if I select “Advanced”->“Show preview packages” I see 2.1.0 and 2.1.1. Neither are marked as preview though. So what is the actual most up-to-date non preview version?
Also, any known issues or things to watch out for when upgrading from 2.0.1?
Thanks!
EDIT: Also, was this issue fixed in 2.10 or 2.1.1?

The latest release of the TMP package is version 2.1.1 which is not a preview release. It is the replacement for 2.0.1 for Unity 2019.x.

Please carefully review the release notes on this new release (including each of the preview releases leading to 2.1.1.) to be sure you are aware of all the changes. As usual, be sure to back up your project first.

1 Like

Just to confirm after upgrading to Unity 2019.4.6f1 and 2.1.1 the problem is still there. The workaround is still the same.

if (m_CaretVisible == false || m_TextComponent.canvas == null)
                return;