Search Unity

Weird bug -- linux related?

Discussion in 'Linux' started by Ryu_18, Feb 4, 2020.

?

Have you had issues that requried re-inserting objects in the Unity inspector, or restarting

  1. No

    0 vote(s)
    0.0%
  2. Yes, with Linux

    0 vote(s)
    0.0%
  3. Yes, with Windows

    0 vote(s)
    0.0%
  4. Yes, with Mac

    0 vote(s)
    0.0%
  1. Ryu_18

    Ryu_18

    Joined:
    Mar 4, 2017
    Posts:
    1
    Hi, I am new to the forums, so if this is not the right place for this, please do let me know. I checked out the bug report section first, but it seems they need to be able to exactly reproduce the bug, but that does not seem to be possible.

    SHORT VERSION

    After leaving Unity open over night, my pathfinding algorithm stopped working. The error was finally resolved by re-inserting the public variables in the inspector. I'm curious if this bug is related to linux (I am using Ubuntu 19.10), and if anyone else has come across it. It is troublesome if something like this could happen in a bigger project.

    MORE DETAILED VERSION

    For context, I am writing a pathfinding algorithm (just simple Dijkstra searching a grid). My "worldGrid" object has a script on it called
    GridContainer
    , which assumes all the children of worldGrid have a
    GridItem
    component, and stores them in a member variable list
    List<GridItem> children
    .

    Code (CSharp):
    1.  void FindChildren(){
    2.         children=new List<GridItem>();
    3.         foreach(Transform child in transform){
    4.             children.Add(child.GetComponent<GridItem>());
    5.         }
    6.     }
    My
    PathFinder
    component is also on the worldGrid object, and has two public variables that I assign through the inspector:

    Code (CSharp):
    1. public GridItem begin;
    2. public GridItem end;
    Where
    begin
    and
    end
    are the begin and end points for which a path must be found. Since the Dijkstra algorithm works with nodes, I defined a class inside the
    PathFinder
    class, called
    Node
    (I assume there are classes already available for this, but that should not be related to the bug), where
    Node
    has a reference to a
    GridItem gridItem
    , and reference to the previous node
    Node prev
    (which is set to null by default). Now, for the algorithm I need to make a
    Node
    for every
    GridItem
    , which I do as follows:

    Code (CSharp):
    1. Dictionary<GridItem, Node> allNodes=new Dictionary<GridItem,Node>();
    2.         foreach(GridItem gridItem in gridContainer.children){
    3.             allNodes.Add(gridItem, new Node(gridItem));
    4.         }
    So this Dictionary is basically just an array with the
    GridItem
    as the key, the logic behind it being that if I need to find the
    Node
    for
    begin
    or
    end
    , I can simply do

    Code (CSharp):
    1. Node node=allNodes[begin]
    or

    Code (CSharp):
    1. Node endNode=allNodes[end]
    This worked exactly as I had intended, and the algorithm was working fine last night before I went to bed. When I woke up and run it again (without changing anything) suddenly my pathfinding failed. I was receiving an error that said that there was no key for the Dictionary for
    Node endNode=allNodes[end]
    . I started the debugger, looked at the Dictionary, and saw that there was a
    GridItem
    key in the Dictionary with the exact same name as
    end
    , but it was still saying that there was no key. I then logged the
    GetInstanceID()
    of the
    end
    and all the
    GridItem
    s of the
    allNodes
    List, and saw that
    end
    had an id of about 2000, where all the
    GridItems
    s had ids of about 4000. So I went to the editor re-dragged the object from the Hierarhcy into the
    end
    field in the inspector, and bam, everything worked again. I assume that if I had restarted Unity, that would've fixed the problem too.

    So my understanding is that after leaving Unity on over the night, the value in the inspector for
    end
    became a copy of the original object, rather than a reference. It took me about 40 mins to figure out what was going on, and this is a super tiny project, and I worry for something like this happening in a large project. So has anyone else encountered something like this?