5 years ago
Hi all!
I have started developing a racing game on my Gamebuino Meta, and I have been encountering lots of random runtime issues as my game grew bigger.
To describe quickly my game, it's a racing game with an Outrun-like view, so I need buffers to store the depth of each line, the curvature of the road (turns & hills), positions of sprites, etc. I am using the full TFT resolution, with 16-bit colours, so I am very cautious on my implementation. Of course, graphics are generated on the fly and fed through "DMA" accesses to cope with the lack of a big frame buffer.
Everything was fine at first, everything was stored in big static buffers, and my first prototypes were running smoothly. As I started adding features, strange stuff started to happen: my color palettes began to shift, after which one of the LEDs started blinking at the same rate as my palette swapped (funny, hey?), and file reading through the SD library was limited to 256 bytes (read() returned -1 as soon as I started reading the 257th byte).
gb.getFreeRam() return ~7kB, so that does not look like a collision between the stack and the heap.
I started suspecting a side effect of memory fragmentation, so I started implementing my own memory management, in an 8kB global buffer. And everything came back to normal. Until today, I am starting to add sprites, and my palette restarts shifting. I still have 700 bytes in my custom buffer, 6kB in gb.getFreeRam(), only instances of PODs (plain old data = base types) on the stack.
Sorry for the fuzzy description, but I don't understand at all what can happen. I suspect I am hitting some limit (hard? soft?), and I cannot continue my game (I can display 1 sprite, and if I have 2 of them, none appear). I am quite knowledgeable of C++ and software development, but not on embedded platforms, and I suspect I lack a bit of experience on this matter.
Any explanation, suggestion of test or anything would be greatly appreciated :-)
Update: I was wondering if some addresses were reserved and I could be hitting them by mistake, thus explaining why my palette and the LEDs were altered simultaneously
NEW 5 years ago
I can't answer but i think that you should give a github link on your source to let good enough people have a look on it and and maybe find a solution.
NEW 5 years ago
How do you do images/sprites?
How do you do the direct gb.tft stuff?
What is your config-gamebuino.h
?
Alban
5 years ago
For the moment, sprites are written in PROGMEM space. I'm not sure the performance will follow, I was just trying that when all hell broke loose again :-)
As for gb.tft, I do stuff like that : https://gamebuino.com/creations/high-resolution-without-gb-display
config-gamebuino.h is unchanged. What am I supposed to do with it?
NEW 5 years ago
For the moment, sprites are written in PROGMEM space. I'm not sure the performance will follow, I was just trying that when all hell broke loose again :-)
As for gb.tft, I do stuff like that : https://gamebuino.com/creations/high-resolution-without-gb-display
config-gamebuino.h is unchanged. What am I supposed to do with it?
Sorunome
5 years ago
there is no such thing as PROGMEM
for the samd21: if the buffer is a global variable, making it const
is enough to put it into flash!
As for config-gamebuino.h
you might be able to save 10k ram by adding #define DISPLAY_CONSTRUCTOR Image(0, 0, ColorMode::rgb565)
. Please note you might have to restart the arduino IDE for those changes to go into effect
Glad you figured out your issue, though
NEW 5 years ago
The issue was not software nor hardware, simply a faulty brainware :-) Buffer overflow in some structure, and I have carried this error from the beginning.
Thanks all!
NEW 5 years ago
Cool that you found it Alban, was near impossible for us to find without the code else...
NEW 5 years ago
Yep, I wasn't desperate enough to call for a specific debugging, I expected some advice on stuff I wouldn't be aware of, or suggestions of tools for instance. And the state of my code was pretty shameful to be honest ;-) When I am satisfied, I'll post a little demo and my codebase.
NEW 5 years ago
there is no such thing as PROGMEM
for the samd21: if the buffer is a global variable, making it const
is enough to put it into flash!
As for config-gamebuino.h
you might be able to save 10k ram by adding #define DISPLAY_CONSTRUCTOR Image(0, 0, ColorMode::rgb565)
. Please note you might have to restart the arduino IDE for those changes to go into effect
Glad you figured out your issue, though
NEW 5 years ago
Hi all (and happy new year by the way!)
I told you that I would post a demo of my game. Here it is :-) https://gamebuino.com/creations/project88
Thanks for the help!