Probable mistake in GraphOwnerInspector.OnDestroy()

Forums 💬 NodeCanvas ⚙️ Support Probable mistake in GraphOwnerInspector.OnDestroy()

  • This topic has 0 replies, 3 voices, and was last updated 7 years ago by Gavalakis.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16894
    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 😉

      #16898
      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).

        #16897
        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

          #16896
          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

            #16895
            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.