Unsolved Bug QPainter crashes
-
@dheerendra
Good catch. \o/ -
Snake is a class and snake is an member vector. In this case snake is also an instance. I made the whole code available at: https://github.com/Sproza/Snake. Board itself works fine. NOTE: drawLine() in paintEvent of both Snake and Board class was only for debugging purposes forgot to delete it sorry.
-
Board class alone works fine. Still no clue about Snake class though :/
-
On a side note, modifying your
pen
andbrush
objects after setting them onpainter
won't modify what painter draws. You should first configure them and once that done set them on painter. -
thanks @SGaist! it should be obvious, a silly mistake on my part. Any ideas about the problem though??
-
What's the size of your
snake
variable ? 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. -
Please? Anyone?
-
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 >= ? -
-
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. -
Ok, since you can run it then why not just find the crash with the debugger ?
When it crash the call stack will be shown and you can easy see where the crash happened.