SFML community forums

Help => Graphics => Topic started by: RedTheGreen on July 28, 2012, 10:54:03 pm

Title: Crash when Setting Sprite Values
Post by: RedTheGreen 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.
Title: Re: Crash when Setting Sprite Values
Post by: eXpl0it3r on July 28, 2012, 11:35:48 pm
You should probably read this (http://en.sfml-dev.org/forums/index.php?topic=5559.0) 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). ;)
Title: Re: Crash when Setting Sprite Values
Post by: RedTheGreen 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.