Probable mistake in GraphOwnerInspector.OnDestroy()

NodeCanvas Forums Support Probable mistake in GraphOwnerInspector.OnDestroy()

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #14081
    erwan
    Participant

    While making sure breakpoints worked in my improbable setup of NodeCanvas I found that in GraphOwnerInspector.cs line 38 :

    Should probably read :

    You probably caught that one already but here it is 😉

    #14096
    Gavalakis
    Keymaster

    Hey!
    owner == null is actually on purpose 😛 and it is a hack to cleanup the graph if the component is removed from the Unity inspector (right click -> remove component for example).
    It’s not really important though, since the GC will clean that up anyway on an enter/exit play mode (as well as other cases).

    Join us on Discord: https://discord.gg/97q2Rjh

    #14105
    erwan
    Participant

    Not wanting to appear anoying but conditionals are resolved left to right so in this case :
    owner == null && owner.graph != null
    If the following is true :
    owner == null
    then owner will be null and when the next conditional will be resolved (because it is a &&) it will crash because you are using owner : owner.graph != null

    #14112
    psykaw
    Participant

    You’re both almost right.
    owner == null could return true but owner could be not null (will be destroyed at the end of the frame). == operator is overriden by Unity.

    To prevent null ref exception you should replace condition with this code:
    owner == null && !ReferenceEquals(owner, null) && owner.graph != null

    #14117
    erwan
    Participant

    Haa ok I failed to see the overload.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.