Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Bug Null Reference at TMPro.TMP_InputField.LateUpdate when deselecting an InputField on Android

Discussion in 'UGUI & TextMesh Pro' started by Good_Punk, Aug 22, 2020.

  1. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    08-22 17:59:07.438: E/Unity(11229): NullReferenceException: Object reference not set to an instance of an object at TMPro.TMP_InputField.LateUpdate () [0x00374] in <ddffaf892bea4155beefcadeaf3d8102>:0

    I get this error, when the InputField is currently selected and I call the Select() method on a button (to close the keyboard). Doesn't happen in the Editor but on Android devices.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    See the following thread and potential change to see if that resolves the issue you are running into?
     
  3. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    I don't think it's the same issue. I don't get the null reference from my script but it happens in Textmesh Pro itself. I only select a button and otherwise don't do anything with the inputfield, so I can't check for null pointers on my side.
     
  4. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    The error happens in TMP_InputField.cs on line 1617:

    Code (CSharp):
    1.             if (m_SoftKeyboard.status != TouchScreenKeyboard.Status.Visible)
    2.             {
    3.                 if (m_SoftKeyboard.status == TouchScreenKeyboard.Status.Canceled)
    4.                     m_WasCanceled = true;
    5.  
    6.                 OnDeselect(null);
    7.             }
    Probably the TouchScreenKeyboard was closed by the button selection (which is what I was going for) and is now null
     
  5. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    Can anybody confirm this?
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    I would need to be able to reproduce the behavior to understand why this error occurs at that particular line given there is already a null check for m_SoftKeyboard in that same function above.

    Are you able to reliably reproduce this error? Can you provide me with a repro case or bug report?
     
  7. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    I've provided a bug report with a sample project: http://fogbugz.unity3d.com/default.asp?1273631_hahuc5n9ue6pc0ff

    It's just a method that gets called on "OnValueChange" from the input field and if the input fields length is above 5 letters it selects a button. That triggers the Null Reference on my LG7 ThinQ.
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Thank you for submitting the bug report.

    I will try taking a look tomorrow or over the weekend and follow up with you as soon as I have more information.
     
    Good_Punk likes this.
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    I was able to take a closer look at the bug report you submitted and have identified the source of the issue.

    The fix is trivial and as follows:

    upload_2020-8-28_15-35-19.png

    I didn't want to suggest adding a null check for m_SoftKeyboard until first understanding why it could be null given its state is already in this same function.

    As it turns out, the value changed event is called after the initial null check on m_SoftKeyboard where it ends up null as a result of the deselection of the input field in your validation code.
     
  10. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
  11. realragnvaldr

    realragnvaldr

    Joined:
    Jul 21, 2019
    Posts:
    41
    I'm getting the same error. Given that this is a year (and a few TMP updates) later, I guess it must be something different.

    This is what i get:

    upload_2021-8-5_18-22-38.png

    NullReferenceException: Object reference not set to an instance of an object.
    at TMPro.TMP_InputField.SendTouchScreenKeyboardStatusChanged()
    at TMPro.TMP_InputField.LateUpdate()


    I use the InputField for the chat function in my app. It goes fine 99% of the time, but now and then i get this error. The last time i got the error (a few minutes ago), i think the app was doing a rebuild/refresh of the chat page while i was typing, but i'm not 100% sure of this.

    @Stephan_B: Any pointer to what may be causing this and how i can solve it?

    I'm using TMPro 3.0.6 and Unity 2020.3.13f.

    Please let me know if you need more information. Thanks!

    EDIT: I just noticed in the catlog that right before the error, there was a Debug.Log() message from my app saying that the app had just come back into focus (OnApplicationFocus) -> hence, it seems that the keyboard was no longer on the screen when the error occurred (... but perhaps this was already obvious to you :))

    EDIT2: Ugh, now i had another one, but this time right before the application came back in focus, so the keyboard must still have been on the screen

    upload_2021-8-5_19-29-37.png
     
    Last edited: Aug 5, 2021
  12. realragnvaldr

    realragnvaldr

    Joined:
    Jul 21, 2019
    Posts:
    41
    For those of you having the same problem, the following should probably work as a temporary fix:

    1. Move the TMPro folder (com.unity.textmeshpro@3.0.6) from the Package cache folder (ProjectName\Library\PackageCache) to your package folder (ProjectName\Packages)

    2. Enable write permission on the files in this folder

    3. Make the following change in TMP_InputField.cs:

    upload_2021-8-6_7-37-15.png

    (The moving is necessary because otherwise package manager will automatically change it back to the code of the official release)
     
    Last edited: Mar 10, 2022
  13. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The above null check will be included in the next release of the TMP package.
     
  14. therobby3

    therobby3

    Joined:
    Jan 30, 2019
    Posts:
    131
    Also receiving tons of these errors in my error log from players after upgrading from 2019 to 2020 and after upgrading to TextMeshPro 3.0.6. Any idea when the next release will be that fixes this issue?
     
  15. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    3.2.0-pre.2 was released this week. This preview package should be visible in Package Manager when enabling seeing preview packages in 2020.x.
     
  16. therobby3

    therobby3

    Joined:
    Jan 30, 2019
    Posts:
    131
    Ok, thanks for the post.

    Unfortunately though, it looks like upgrading to that version of TextMeshPro screws my textfields up. Here is an example below:

    Attached images of same textfields using 3.0.6 and 3.2.0-pre.2 are attached. Note, pre.1 has the same issue.
     

    Attached Files:

  17. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Did you update the TMP Essential Resources after switching to Preview 1 & 2 as per the Upgrade Note?

    In preview 1, the shaders were updated for compatibility reasons with SRP where using the previous shader (from 3.0.6) in Preview 1 or 2 would result in the white blocks as seen in your image.
     
  18. therobby3

    therobby3

    Joined:
    Jan 30, 2019
    Posts:
    131
    Ah, I guess I shoulda read that. Thanks, it works now!
     
    Stephan_B likes this.
  19. unity_HHEcGUR7CMJGoQ

    unity_HHEcGUR7CMJGoQ

    Joined:
    Jun 28, 2022
    Posts:
    7
    had the same problem. updated the tmpro but now there is another error message.

    NullReferenceException: Object reference not set to an instance of an object. TMPro.TMP_InputField.OnSubmit (UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0) TMPro.TMP_InputField.LateUpdate () (at <00000000000000000000000000000000>:0)

    turns out eventData is null. need to add another null check
    Edit:
    Code (CSharp):
    1. public virtual void OnSubmit(BaseEventData eventData)
    2.         {
    3.             if (!IsActive() || !IsInteractable())
    4.                 return;
    5.  
    6.             if (!isFocused)
    7.                 m_ShouldActivateNextUpdate = true;
    8.  
    9.             SendOnSubmit();
    10.             DeactivateInputField();
    11.             eventData?.Use();
    12.         }
     
    Last edited: Aug 29, 2023
    msosnin likes this.
  20. thadeuconstantinosantos

    thadeuconstantinosantos

    Joined:
    May 3, 2023
    Posts:
    3
    This validation fixed this problem, PLEASE, update the TMPro.

    NullReferenceException: Object reference not set to an instance of an object.

    TMPro.TMP_InputField.OnSubmit (UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0)
     

    Attached Files:

    Last edited: Sep 29, 2023