NullReferenceException in GraphOwnerInspector.OnDestroy

Forums 💬 NodeCanvas ⚙️ Support NullReferenceException in GraphOwnerInspector.OnDestroy

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #17027
    erik
    Participant

      Hey,
      I get this error when I have the Canvas open during play and destroy the scene of which the FSM owner is part of.
      It’s not fatal or anything, just annoying. 😉

      NullReferenceException: Object reference not set to an instance of an object
      NodeCanvas.Editor.GraphOwnerInspector.OnDestroy () (at Assets/ParadoxNotion/CanvasCore/Framework/Design/Editor/Inspectors/GraphOwnerInspector.cs:42)

      Looking at the code it’s quite obvious…

      #17032
      Gavalakis
      Keymaster

        Hey,

        Yeah, This is actually a hacky line of code there, which “works” in editor due to how unity objects handle null operators.
        I will have fix this in a more proper way.
        Thanks 🙂

        #17031
        sugoidev
        Participant

          Maybe I misunderstood your reply, but I think the reported issue is that this

          if (owner == null && owner.graph != null){

          will always throw depending on the order Unity destroys the object.
          It will try to evaluate owner.graph when owner is null.
          The fix is to use

          if (owner != null && owner.graph != null){

          so owner.graph is touched when owner is not null.

          #17030
          psykaw
          Participant

            The right fix is:

            If owner equals to null (could have been destroyed but is not null) so you check if owner is really null with ReferenceEquals and if not continue.

            #17029
            sugoidev
            Participant

              If it is fake-null (when owner == null is true, but ReferenceEquals(owner, null) isn’t), won’t accessing its members throw with message “The object of type TYPE has been destroyed but you are still trying to access it.”?

              #17028
              Gavalakis
              Keymaster

                What I do there is very hacky, but considering that the hack is kept, then @psykaw’s code is the “correct” fix. Truth is that the whole OnDestroy method there is not really mandatory, since the object will be cleaned up anyway, but is rather a mini-convenience cleanup, which is not critical at all.
                @sugoidev, if ‘ReferenceEquals(owner, null) == false’, then the ‘owner.graph’ will of course not be accessed 🙂

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