Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Using a NativeArray in a recursive call creates a stackoverflow

Discussion in 'Scripting' started by afuzzyllama, Aug 17, 2018.

  1. afuzzyllama

    afuzzyllama

    Joined:
    May 19, 2010
    Posts:
    20
    Hi All,

    I'm using a NativeArray in the following way:

    Code (CSharp):
    1.  
    2. public void FreeSelfAndChildren(int index)
    3. {
    4.     if (index == -1)
    5.     {
    6.         return;
    7.     }
    8.  
    9.     var item = _mem[index];
    10.     FreeSelfAndChildren(_mem[index].ChildIndex);
    11.     Free(index);
    12. }
    13.  
    When I call this code I get a stackoverflow on the following line:
    Code (CSharp):
    1. var item = _mem[index]
    Anyone else experience this?
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    1. What's the value type you're dealing with?
    2. What's the approximate depth of your recursion?
     
  3. afuzzyllama

    afuzzyllama

    Joined:
    May 19, 2010
    Posts:
    20
    I'm using a custom struct. The call depth is 1-3 deep at this point.
     
  4. afuzzyllama

    afuzzyllama

    Joined:
    May 19, 2010
    Posts:
    20
    It was a bug in my code, nothing to see here!