Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Strange bug with drawing sprites.  (Read 1857 times)

0 Members and 1 Guest are viewing this topic.

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Strange bug with drawing sprites.
« on: August 10, 2014, 06:25:21 am »
I am getting a strange bug when I try and display sprites. It is 100% my fault somewhere in my code, and I have been trying to narrow it down. I'm just asking for more ways to narrow it down. I have a loop that loops over this line:
rWindow.draw( (**it_comp).getSprite() );

1. There are a total of 7 sprites, and I confirmed that the loop is calling that function 7 times, so it is definitely attempting to draw the sprites.
2. I have also confirmed that the 7 sprites all have acceptable values for these:
 color
 position
 texturerect
 scale
3. Because of position, I can look right at the spot the sprite should be, but it is not there. What other values of the sprites could I check to see if they are causing them to be invisible?
4. I know it's not hiding behind other sprites. Unless it can hide behind the background fill color of the window.


More detailed explanation(but not necessary to answer above question):
1. The bug disappears when I use a debugger (not my question): http://stackoverflow.com/questions/7112436/c-vs-2010-bugs-occur-only-when-running-without-a-debugger
2. The bug occurs somewhat randomly to certain sprites.
3. The bug only occurs if I initialize a new graphics component in a somewhat strange way, but that shouldn't be causing any problems.
4. Because the debugger never gives a warning(it does If i have seg faults or bad memory) I know it's not some sort of pointer problem (right?)

I have a graphics component factory which holds graphics components. Each graphics component holds a sprite. There is a loop that loops over these graphics components, gets a const reference to the sprite, and as you can see, uses the window to draw it.
The view never changes, and I have checked those 4 values for strange readings and they all come back normal. I'm not sure what else to check.
« Last Edit: August 10, 2014, 06:32:30 am by Strikerklm96 »

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: Strange bug with drawing sprites.
« Reply #1 on: August 10, 2014, 07:16:52 am »
You're asking to suppose the source of your problems without the source (pun intended) code. Anyway:
« Last Edit: August 10, 2014, 07:25:27 am by Strelok »

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Strange bug with drawing sprites.
« Reply #2 on: August 10, 2014, 07:33:34 am »
I'm just asking for more ways to narrow it down.
That means I want a way to check the state of a sprite. The source code is too long and complicated. I will give a simplified version within the next 10 hours though (I have simplified it partially. I have to go to bed now.

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Strange bug with drawing sprites.
« Reply #3 on: August 10, 2014, 09:17:43 pm »
I figured it out.
One of the values for the sprites that I forgot to check was the angle of it, which in this case sometimes became NAN! Once I discovered this, I was quickly able to find what caused it, which in this case was an uninitialized variable.

That was what I was asking for, more values to check to make sure the sprite wasn't in an invalid state, not for anyone to read my code.
« Last Edit: August 10, 2014, 09:23:54 pm by Strikerklm96 »

 

anything