Search Unity

TMP_InputField GenerateCaret m_TextComponent.canvas exception

Discussion in 'UGUI & TextMesh Pro' started by paulgullettMR, Jul 28, 2020.

  1. paulgullettMR

    paulgullettMR

    Joined:
    Jun 23, 2019
    Posts:
    13
    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

    Code (CSharp):
    1.     (Filename: currently not available on il2cpp Line: -1)
    2. 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.
    3.       at TMPro.TMP_InputField.GenerateCaret (UnityEngine.UI.VertexHelper vbo, UnityEngine.Vector2 roundingOffset) [0x00000] in <00000000000000000000000000000000>:0
    4.       at TMPro.TMP_InputField.OnFillVBO (UnityEngine.Mesh vbo) [0x00000] in <00000000000000000000000000000000>:0
    5.       at TMPro.TMP_InputField.UpdateGeometry () [0x00000] in <00000000000000000000000000000000>:0
    6.       at TMPro.TMP_InputField.Rebuild (UnityEngine.UI.CanvasUpdate update) [0x00000] in <00000000000000000000000000000000>:0
    7.       at UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () [0x00000] in <00000000000000000000000000000000>:0
    8.       at UnityEngine.Canvas+WillRenderCanvases.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    9.     UnityEngine.UI.CanvasUpdateRegistry:PerformUpdate()
    10.     UnityEngine.WillRenderCanvases:Invoke()
    I can get rid of the exception by adding the following to the top of GenerateCaret

    Code (CSharp):
    1. if (m_CaretVisible == false || m_TextComponent.canvas == null)
    2.                 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.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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.
     
    Last edited: Jul 30, 2020
  3. paulgullettMR

    paulgullettMR

    Joined:
    Jun 23, 2019
    Posts:
    13
    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.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I made the suggested change which will be in the next release of the TMP package.
     
  5. James15478

    James15478

    Joined:
    Apr 2, 2013
    Posts:
    91
    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?
     
    Last edited: Aug 17, 2020
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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.
     
    James15478 likes this.
  7. paulgullettMR

    paulgullettMR

    Joined:
    Jun 23, 2019
    Posts:
    13
    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.

    Code (CSharp):
    1. if (m_CaretVisible == false || m_TextComponent.canvas == null)
    2.                 return;