Stack overflow with vex v5 robot brain

I have a stack overflow in my program that I’ve been making for a while now, is there a way to get around this roadblock?

I’m only around halfway done with the project and it would probably need to take much more memory than what it’s currently using.

which programming environment ?

I’ll assume VEXcode for now.
The stack is fixed for each task and should only be used for a small number of local variables. If you need a lot of storage use either global storage or dynamically allocated memory.

4 Likes

I’m using vexcode v5, switched to pro to see if that would fix something, it didn’t.

I have no idea how memory works, how would I use global or dynamic storage? Thx for ur help.

you need to post some of the code that has issues and I will suggest something. Have you figured out which task is the memory hog ?

3 Likes

I haven’t the code as is right now is around 1100 lines and I’m expecting to have to use more memory in the future. Is there anyway to add memory to the robot instead?

ok, I don’t need to see all of it, unless everything is running as one task.

That’s not the issue, and no, memory is fixed.
basically, never do this

void foo() {
    int bigarray[10000];

    // etc.
}

crude way to fix would be this.

void foo() {
    static int bigarray[10000];

    // etc.
}
4 Likes

Ohhhh, would having a lot of 16 by 16 color arrays set it off?

I also have a good amount of classes in classes that have arrays in them.

probably

yea, but don’t make the variables inside the class static, make the class instance static if they are causing issues (or allocate memory for them, but that’s a whole other level of complexity I’m not going to get into here)

4 Likes