Closed Jonny999999 closed 11 months ago
Found issue.
renderGameToArray()
in map.c accesses game.snake.tail[]
at invalid position when recently grown.
swap execution order of snakeGrow();
and placeFood();
in game.c:
https://github.com/Jonny999999/snake-pp/blob/ad1dd7f5c356fff93acea649dc1e9aacf8ad9289/src/game.c#L106-L110
modify snakeGrow()
in snake.c at:
https://github.com/Jonny999999/snake-pp/blob/ad1dd7f5c356fff93acea649dc1e9aacf8ad9289/src/snake.c#L34-L42
so the element is actually valid
decrease snake length index at map render (might cause issues with printMap()
though):
https://github.com/Jonny999999/snake-pp/blob/ad1dd7f5c356fff93acea649dc1e9aacf8ad9289/src/map.c#L26-L30
replace for loop with for (int i = 0; i < snake.length -1; i++)
fixed with "solution 1" for now in: cf92191177cfeee99b7971d6dd02b3dce027d62d
Tested with ad1dd7f5c356fff93acea649dc1e9aacf8ad9289
crash output
steps to reproduce:
option1: play game and collect food until crash
option2: run snakeGrow() and placeFood() for certain count
when running both those functions produces crash! Add this to runGameCycle():
debugging / things tried
effect of start length:
start with
length = 2
=> crashes atgame.snake.length=12
start withlength = 4
=> crashes atgame.snake.length=14
(2 tests) start withlength = 12
=> crashes atgame.snake.length=20
(2 tests)effect of run duration:
run without picking up food => no crash in 5 minutes
run snakeGrow() repeatedly:
no crash when running snakeGrow() every 5 cycles
run placeFood() repeatedly:
no crash when running placeFood every cycle
comment out complex food placement:
replacing placeFood() content with simple assignment results in no crash! must be food placement algorithm