#StackRunning Out of Range

1 messages · Page 1 of 1 (latest)

brittle berry
#
public struct MyStack 
{
    
    public NativeArray<int> stack;
    int count;
    public MyStack(int size)
    {
       stack = new NativeArray<int>(size,Allocator.Persistent);
        count = 0;
        
    }
    #region methods
    public void EnQueue(int item)
    {
        
        stack[count] = item;
        count++;
       
    }
    public int DeQueue()
    {
        
        count--;
        return stack[count];
    }
    #endregion
}

I wrote this code for my stack, but it keeps on running out of range, can somoene give me advice on how I can find the source of the issue?
That s the second script, which works in pairs with the stack
https://paste.ofcode.org/32v8gV7qzqPS5JmfufVkGXi

scarlet drift
brittle berry
#

yes

scarlet drift
#

What's to stop you from going out of range

brittle berry
#

because it s not supposed to run out of range

scarlet drift
#

It depends on the size you allocate vs how much you enqueue

brittle berry
#

yes that s why I posted my code, but my innitial question is that if Im not using additional threads is it possible that the copiler messes up some numbers because the list is constantly changing?

scarlet drift
#

No?

#

What list?

brittle berry
#

the stack, my struct it s a native array

scarlet drift
#

You probably should use a NativeList so it can resize