Search Unity

Bug Frequent UIElements Exceptions make Debugging Painful

Discussion in 'UI Toolkit' started by Thygrrr, Mar 20, 2023.

  1. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    rider64_n3Voa0kpuB.png

    Unity 2022.2 - I regularly get this (or similar) exception if a domain reload / recompile happens while my debugger is connected.

    This is super aggravating, because it pauses the compile/reload until it is acknowledge, and it's not even possible to resume from there. (resume button in Rider is grayed out) - so I have to stop my debug session.

    Besides often leading to compilation delays and lost debug sessions, it also means I need to remember to reconnect or miss out on an exception I do want to catch.

    This IllegalArgumentException is just disruptive - it's unity's own code (mostly in ECS, but also many other things) that frequently occurring case should be handled way, way more gracefully.

    May I suggest just returning null and logging a Warning instead of throwing? :p
    It would be the expected behaviour of Q on a null VisualElement anyway, from my perspective.
     
    Last edited: Mar 21, 2023
  2. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    572
    Can you file a bug with this? Clear instruction on how to reproduce the bug will help identify all affected versions.
     
  3. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Hmm, thanks.

    Do your bug report testers debug this using Rider? Otherwise I can't give a repro, it is dependent on an external debugger being connected, because otherwise, the domain reload often just hides the exception. (I think there is no logging during that "Completing Domain" period.)


    I'll think I'll just file the Bug with the ECS Team instead and patch UI Elements to work around this myself.

    A dash of self healing systems / defensive programming could go a long way here in this extension method instead of insta-throwing on what actually is a semantically perfectly sensible value.

    I do think no UI Elements code should run during domain reload, however - maybe that's the real mystery here.
     
    Last edited: Mar 21, 2023
  4. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    572
    We will do the most we can to get the bug reproduced, and we do have rider licenses.

    But I think the exception will still be logged in the editor log file without any debugger attached to it.

    Unfortunately, I don't think we can do something on the Ui toolkit side. Calling a class method on a null class usually throw an exception. Even if this is an extension method, the goal is to use it as a class method and as such the same constraints are expected from the programmer.

    I will see with the team if adding a [NotNull] attribute to the signature would be possible, as it may help code editors and static analyzers to prevent such issues.
     
  5. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    I have this problem too, each time I need to restart unity editor or the hirarchy window is simply broken