I have a pretty large number of objects being initialized in the setup() function and it seems like I’ve hit some type of limit that I’m not sure how to approach.
I’m observing the crash in ardens as well as Felipe’s emulator.
I have plenty of mem available:
arduino-cli compile --fqbn "arduboy-homemade:avr:arduboy" --optimize-for-debug --output-dir . Sketch uses 20680 bytes (72%) of program storage space. Maximum is 28672 bytes. Global variables use 2292 bytes (89%) of dynamic memory, leaving 268 bytes for local variables. Maximum is 2560 bytes.
Ardens stack trace:
I have a branch where the latest commit causes the runtime error with the binaries committed (can build from scratch on linux using
./setup.sh to install everything assuming have the arduino-cli, then just
uint8_t cursor; as a private member to one of my classes causes this issue.
This is a bit odd since the stack trace is showing the error occurs during what I believe is a poll to the timer.
Another thing I noticed is playing arround with pulling out writes to some of my member vars in the functions called in setup seem to get passed the error. Like puling out:
world = WorldEngine(&arduboy, &state, &engine, &menu2);
from the setup() function solves this runtime issue for example. Digging in there a little bit I have a feeling this is a red herring error being caused by me corrupting memory or something of the like. Any tips on how to approach debugging this would be appreciated.
I’m digging around in ardens some more an I noticed that the stack under the CPU dataspace shrinks as I add more variables, to the point of it rolling over and overflowing, so It looks like this is a real overflow issue. That leaves me wondering why this is occurring though. I’ve also noticed that the stack usage doesn’t change at all during gameplay. It looks like I need to reduce the global vars I’m using to free-up some space.