Bug QPainter crashes
-
On a side note, modifying your
penandbrushobjects after setting them onpainterwon't modify what painter draws. You should first configure them and once that done set them on painter. -
What's the size of your
snakevariable ? Are you sure the coordinates are valid ? -
Yes, coords are valid (250x and 250y whereas border is 500x500). Size of snake vector is 2.
Whole code is available at: https://github.com/Sproza/Snake.git
Just to make it clear because many find it confusing: Snake is a class with snake member vector and I named an instance of Snake "snake" in mainwindow constructor. -
Can you provide a more complete code sample ? We can only do guesses here since there are a lot of unknowns from your side.
-
Hi
The code on git do not really compile out of the box.
Anyway, i saw thisfor(int i = snake.size(); i >= 0; i--)
if snake.size() is 0 , wont that crash in snake[0].x ?
as you say >= ? -
Hi
The code on git do not really compile out of the box.
Anyway, i saw thisfor(int i = snake.size(); i >= 0; i--)
if snake.size() is 0 , wont that crash in snake[0].x ?
as you say >= ? -
Yes, in that case it will crash, but snake.size() will never be 0 unless board -> STARTING_LENGTH will be 0. In Snake constructor program pushes additional dot to vector STARTING_LENGTH times.
But in reality there wont be way to change STARTING_LENGTH to 0 via menu.
So I do no think that's the reason. Just to be sure I tried snake.size() - 1 (although i have no idea why it would work) and it is not the solution. -
Yes, in that case it will crash, but snake.size() will never be 0 unless board -> STARTING_LENGTH will be 0. In Snake constructor program pushes additional dot to vector STARTING_LENGTH times.
But in reality there wont be way to change STARTING_LENGTH to 0 via menu.
So I do no think that's the reason. Just to be sure I tried snake.size() - 1 (although i have no idea why it would work) and it is not the solution.