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

Author Topic: Crash when Setting Sprite Values  (Read 1120 times)

0 Members and 1 Guest are viewing this topic.

RedTheGreen

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • RedTheGreen's Website
    • Email
Crash when Setting Sprite Values
« on: July 28, 2012, 10:54:03 pm »
void sursprite::Add()
{
    main.SetSubRect( sf::IntRect( aX[aIndex], aY[aIndex], ( w + aX[aIndex] ), ( h + aY[aIndex] ) ) );
    sprite_queue.push_back( *this );
}
At line 3 in the above function, my program crashes. aX & aY are equal to zero. w & h are equal to 32.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10836
    • View Profile
    • development blog
    • Email
Re: Crash when Setting Sprite Values
« Reply #1 on: July 28, 2012, 11:35:48 pm »
You should probably read this first before posting. ;)

Anyways my magicball is telling me that aIndex goes beyond the allowed bound, thus crashing with an access violation or if aX and aY indeed are vectors then with an assert error... Now the view has gone dark and I can't predict anything further. ;D

Also is sprite_queue a global object (which you shouldn't do)? Otherwise I don't see any sense in push *this back into a vector (actually that's also not so nice to do, but at least you've made use of vectors). ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

RedTheGreen

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • RedTheGreen's Website
    • Email
Re: Crash when Setting Sprite Values
« Reply #2 on: July 29, 2012, 03:53:09 am »
I'll keep that in mind from now on, thanks. :P

Yep, that was it. I forgot to set a value to aIndex.

sprite_queue is a global list. I run through it each drawing cycle. When parsing a new map or exiting the program, it clears the list. I have a separate queue for sf::Image which have corresponding ids.

 

anything