Hello!
In my simple button class I store textures and sprites in
std::vector< std::pair< sf::Sprite , sf::Texture > > states;
It works, but some times i've got this:
Unhandled exception at 0x0f6d2382 in D_D.exe: 0xC0000094: Integer division by zero.
on
target.draw( states [ pos ].first, states_ );
It happens when size of states > 3. I think sprite's link to texture become not valide when std::vector reallocate his memory .
I don't want to use dynamic memory or std::vector::reserve to solve it.
Are there any other solution?
Sorry for my English :)
If you don't want to use 'dynamic memory' then, why do you use std::vector? It also allocates the objects dynamically. ;)
I would advise you against the pairing of sf::Sprite and sf::Texture. sf::Texture is a resource = heavy object and should be handled with care, while the sprite is a very light object.
But in case you really have to/want to/need to, you can simply use a std::unique_ptr:
std::vector< std::pair< sf::Sprite , std::unique_ptr<sf::Texture> > > states;
Btw having two variables with nearly the same names (states vs states_) is a bit misleading. ;)