Search Unity

Collections 0.1.0 NativeQueue bug

Discussion in 'Entity Component System' started by snacktime, Jul 31, 2019.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Enqueue is simply not adding to the queue at times. I cannot duplicate it in a unit test environment. It's not hitting every place I use NativeQueue so far just one feature is all I've noticed.

    I can Enqueue on the main thread and call Count on the next line and it returns 0. And TryDequeue which runs every frame never returns true.

    In this feature it works for the first 2 items and then starts not adding.

    correction: it works the first time only.
     
    Last edited: Jul 31, 2019
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    FYI this is on the latest 2019.1
     
  3. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Ok this is the strangest thing but here is a unit test that shows the failure. It's TryDequeue wrapped in a while that is causing it somehow.

    Code (csharp):
    1.  
    2. [Test]
    3.         public void NativeQueueBugTest()
    4.         {
    5.             NativeQueue<int> requests = new NativeQueue<int>(Allocator.Temp);
    6.  
    7.  
    8.             // Works
    9.             for (int i = 0; i < 2; i++)
    10.             {
    11.                 requests.Enqueue(i);
    12.                 Assert.AreEqual(1, requests.Count);
    13.                 requests.TryDequeue(out int value);
    14.                 Assert.AreEqual(0, requests.Count);
    15.                 Debug.LogFormat("Loop1 Iteration {0}", i);
    16.             }
    17.  
    18.             // Second iteration Enqueue doesn't.
    19.             for (int i = 0; i < 2; i++)
    20.             {
    21.                 requests.Enqueue(i);
    22.                 Assert.AreEqual(1, requests.Count);
    23.                 while (requests.TryDequeue(out int value))
    24.                 {
    25.  
    26.                 }
    27.                 Assert.AreEqual(0, requests.Count);
    28.                 Debug.LogFormat("Loop2 Iteration {0}", i);
    29.             }
    30.  
    31.             requests.Dispose();
    32.         }
    33.  
     
    Deleted User likes this.
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    case 1173318
     
  5. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Not sure why it didn't click probably because it was 3am:), but it's TryDequeue against an empty queue that puts it into a bad state.
     
    mkracik likes this.
  6. tarahugger

    tarahugger

    Joined:
    Jul 18, 2014
    Posts:
    129
    I am experiencing this also on long-lived/persistent queues. They work fine initially but after a while they stop being able to have things queued. They fail silently, and stepping over the Enqueue() line in the debugger shows that the count of items doesn't increase. I've had to revert to the older version.

    Edit: I'm on 2019.3.a08/a10
     
    Last edited: Aug 1, 2019
    Deleted User likes this.
  7. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I'm surprised more people aren't up in arms over it, I'm guessing a good number won't notice it immediately due to there are no warnings it just silently fails.
     
    tarahugger likes this.
  8. Deleted User

    Deleted User

    Guest

    bump, I am having a huge memory leak
     
    Last edited by a moderator: Aug 3, 2019
  9. saarg

    saarg

    Joined:
    Mar 9, 2017
    Posts:
    31
    I noticed this too but didn't get a change to narrow it down to the trydequeue but it match my issue I had, nice job @snacktime!

    A also had the memory leak.
     
    Deleted User likes this.
  10. bkaradzic

    bkaradzic

    Joined:
    Jul 18, 2019
    Posts:
    2
    This issue is fixed in [0.1.1-preview] - 2019-08-06.
     
    mkracik likes this.