vectozavr / GameBoy_arduino

Source code of gameBoy from video on YouTube channel "Vectozavr".
MIT License
45 stars 6 forks source link

Infinite recursion cause stack overflow and artefacts on screen #4

Open ivan-klymchuk-rc opened 3 years ago

ivan-klymchuk-rc commented 3 years ago

On setup you call menu() function, which never reach return - because it call fps(), snake() or flappyBird() before return, and inside of this functions you call menu() again on exit, so it never reach return and free stack. After several iterations you'll fill your stack, and start to overwrite program variables, such as screen area. How to avoid that: put your menu to loop, and use return on exit from game, instead of calling menu(). If you want to remember menu state - just use variable for that.