Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback Pixels per point should be positive UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Discussion in 'UI Toolkit' started by taylank, Aug 29, 2019.

  1. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    Hi,

    I'm running into this issue with a custom editor window containing UIElements. Whenever I attempt to load the contents of the window within its enable method, I get the error in the title. Occasionally, but not always, I will also get the error when using InspectorElement to draw default inspectors within my editor window.

    There is no stack trace beyond that.

    It looks like I'm triggering a race condition where content is asked to load before the window has been initialized. Is there a way to avoid this?
     
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    771
    Hey,

    I believe i have reproduced this recently as well. It may occur because invalid values end up being written to
    VisualElement.transform
    .

    One caveat is that when elements have just been created their layout is invalid (their rect is just NaN) so deriving transforms from this does not work.

    To fix this you can wait for the layout to be completed by registering a callback for GeometryChangedEvent on your root element. At that point all layout positions should be valid and can be used for tweaking transforms.
     
    Lahcene and taylank like this.
  3. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    Yup, that was it. Thanks!
     
  4. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    @antoine-unity I encountered this error again recently, and I'd like to make a suggestion to help prevent people running into it. The culprit this time was a combination of my code and bounding box intialization problem.

    In my code I was relying on the bounding box of a visual element to position its children. When the box had NaN values, the children's transform.position properties were also assigned NaN values, which was leading to the "pixels per point" error.

    Is there really any reason why transform.position should allow you to write NaN values to it? Shouldn't the setter throw an exception (or at least a warning) when you attempt that?
     
  5. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    This restriction would probably break other use cases. That said, we need _some_ value for when the value is not yet computed and any real value, like zero, would not convey that this value is not actually real (yet). That is, it's better that everything explodes, in a way, when you try to use these uninitialized values. You don't have to wonder whether someone else set these to zero, or they are zero because they haven't computed yet.
     
    x1alphaz1 likes this.
  6. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    I'm hitting this with Custom Inspector code that was delaying until GCE to wait before doing any layout (because it needs to know the size of the visual area). Everything was working fine until I stopped using custom fields and started using SerializedProperty with PropertyField.

    It seems that something in PropertyField is triggering this, when non-PropertyField code does not.

    The problem though is - as @taylank pointed out - there is no stack trace. Unity is spamming the console with these 'errors' with zero information and nothing that would enable anyone to debug them. An error that can't be acted upon is almost worse than no error at all - it's just useless.

    @uDamian is there a way to trace these, and find out exactly how/why/where they're coming from? At the moment enabling/disabling PropertyFields in my code is the 1-line change that causes them to return/disappear. I suspect a bug in PropertyField - but it could be a bug in my custom PropertyDrawer (NB: I'm using the UIToolkit approved approach to PropertyField, as shared by UIT team member in a different thread -- and my code worked correctly *Before* I started using PropertyField -- so it's less likely a bug in my code).

    I would submit a bug report but ... narrowing this down will take forever without any info from Unity for when/why/where/how the error is being triggered.
     
    x1alphaz1 likes this.
  7. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    Update: I managed to find and fix the code that was triggering this (largely through luck).

    But I noticed that when this NaN situation happens it also breaks UIToolkit - really bad things happen, e.g. the UIToolkit debugger starts misrporting information -- but doesn't display any errors.

    I think this error message should be massively upgraded to be something like:

    "Error: A NaN value was provided as a VisualElement size; this has corrupted your UIToolkit subsystem; the UnityEditor is now in invalid state, the editor may stop working in multiple ways"
     
    x1alphaz1 likes this.
  8. x1alphaz1

    x1alphaz1

    Joined:
    Dec 19, 2020
    Posts:
    23
    this happened today as well when Editor started spamming Console with this message. i believe it's a bug in Unity
    i was changing the properties of a Textmeshpro in inspector during runtime.
    that broke something, some Object names in hierarchy appeared with missing text...

    Anyway the fix turned out to be very simple.
    goto Window-> Layout -> Reset All layouts
     
    lulitha and alexmingsheng like this.
  9. x1alphaz1

    x1alphaz1

    Joined:
    Dec 19, 2020
    Posts:
    23
    goto Window-> Layout -> Reset All layouts
     
  10. UnitysimpleDeveloper

    UnitysimpleDeveloper

    Joined:
    Apr 21, 2023
    Posts:
    1
    thanks for that , it work for me
     
    x1alphaz1 likes this.
  11. mcbombad

    mcbombad

    Joined:
    Mar 3, 2020
    Posts:
    4
    Thanks, this pointed me in the right direction. After Reset All Layouts didn't work, I closed down some of Unity's windows on my second monitor to fix it.
     
  12. unity_544389B6A97A21831075

    unity_544389B6A97A21831075

    Joined:
    Oct 6, 2023
    Posts:
    1
    actually, this is an error occuring only when you open animator tab, close it and you're free to go
     
    mcbombad likes this.
  13. lulitha

    lulitha

    Joined:
    Feb 8, 2017
    Posts:
    11
    thank you
     
    x1alphaz1 likes this.