Search Unity

Resolved "VisualElement.style.visibility" does not work for comparisons in IL2CPP - It gives false results!

Discussion in 'UI Toolkit' started by mikejm_, Dec 14, 2022.

  1. mikejm_

    mikejm_

    Joined:
    Oct 9, 2021
    Posts:
    346
    I have been trying to build to IL2CPP as I am now optimizing performance and I have noticed a funny bug.

    To demonstrate I have a script which modifies the visibility of a given VisualElement based on a public bool:

    Code (csharp):
    1.  
    2. if (setBgVisibilityHidden) {
    3.                 backgroundVE.style.visibility = Visibility.Hidden;
    4.             }
    5.             else {
    6.                 backgroundVE.style.visibility = StyleKeyword.Null;
    7.             }
    Then I have a code that debugs out the following on every mouse click:

    Code (csharp):
    1. if (Input.GetMouseButtonDown(0)) { //click made
    2.  
    3.             Debug.Log("CURRENT VISIBILITY is: " + backgroundVE.style.visibility);
    4.  
    5.             if (backgroundVE.style.visibility == StyleKeyword.Null) {
    6.                 Debug.Log("   style.visibility == StyleKeyword.Null");
    7.             }
    8.             if (backgroundVE.style.visibility != StyleKeyword.Null) {
    9.                 Debug.Log("   style.visibility != StyleKeyword.Null");
    10.             }
    11.             if (backgroundVE.style.visibility == Visibility.Hidden) {
    12.                 Debug.Log("   style.visibility == Visibility.Hidden");
    13.             }
    14.             if (backgroundVE.style.visibility != Visibility.Hidden) {
    15.                 Debug.Log("   style.visibility != Visibility.Hidden");
    16.             }
    17.         }
    The behavior works correctly in Mono to Android and the Editor. However, it does not work properly in IL2CPP built to Android. Here are the outputs with either build method:


    CORRECT (Mono on Android / Editor):

    1) When style.visibility = Visibility.Hidden:

    CURRENT VISIBILITY is: Hidden
    style.visibility != StyleKeyword.Null
    style.visibility == Visibility.Hidden

    2) When style.visibility = StyleKeyword.Null:

    CURRENT VISIBILITY is: Null
    style.visibility == StyleKeyword.Null
    style.visibility != Visibility.Hidden


    INCORRECT (IL2CPP on Android with Android LogCat):

    1) When style.visibility = Visibility.Hidden:

    CURRENT VISIBILITY is: Hidden
    style.visibility != StyleKeyword.Null
    style.visibility != Visibility.Hidden

    2) When style.visibility = StyleKeyword.Null:

    CURRENT VISIBILITY is: Null
    style.visibility != StyleKeyword.Null
    style.visibility != Visibility.Hidden



    It seems this whatever happens in IL2CPP is changing the visibility state setting in a way that we can't properly evaluate using our usual terminology. Is there any short term workaround for ongoing development? Or a long term solution?

    Thanks.

    Bug Report Submitted: IN-25846
    (reproduction project with 89 line code open inside ready to press play)
     
    Last edited: Dec 14, 2022
  2. Maverick

    Maverick

    Joined:
    Dec 18, 2009
    Posts:
    240
    Afaik you should use VisualElement.resolvedStyle when getting current style value.
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,926
    Thanks for the bug report. We will investigate this.
     
    mikejm_ likes this.
  4. mikejm_

    mikejm_

    Joined:
    Oct 9, 2021
    Posts:
    346
    It's been over 4 months and I don't see any updates on the tracker. Any update Josh?

    I appreciate any help. Thanks.
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,926
    mikejm_ likes this.
  6. mikejm_

    mikejm_

    Joined:
    Oct 9, 2021
    Posts:
    346
    JoshPeterson likes this.