#StackRunning Out of Range
1 messages · Page 1 of 1 (latest)
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
You're not doing any range checking here
yes
What's to stop you from going out of range
because it s not supposed to run out of range
It depends on the size you allocate vs how much you enqueue
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?
the stack, my struct it s a native array
You probably should use a NativeList so it can resize