Hi, y'all.
I've been trying to load a series of sprites into a vector via the following loop.
sf::Sprite spritey;
for (unsigned int i = 0, k = 0; i < tobesprited.size(); ++k) {
loadSprite(tobesprited.at(i), &spritey);
mdeckVector.push_back(thisCard);
}
Where loadSprite is
void loadSprite(int textCode, sf::Sprite* spritey) {
//textMap is an unordered_map I keep textures in
auto checkExists = textMap.find(textCode);
if (checkExists == textMap.end()) {
sf::Texture texturey;
char texName[64];
sprintf_s(textName, 64, "./pics/%i.jpg", textCode);
texturey.loadFromFile(textName);
//textMap is an unordered_map I keep textures in
textMap.insert(std::make_pair(textCode, texturey));
spritey->setTexture(texturey);
}
else
spritey->setTexture(checkExists->second);
}
The problem happens at
loadSprite(tobesprited.at(i), &spritey);
spriteVector.push_back(thisCard);
If I check the size of the texture spritey references after I load the sprite, it's exactly what it's supposed to be. But if I check it after spriteVector.push_back, it'll be 3435973836 by 3435973836, except on the penultimate sprite in the vector. Then, if I leave the window, I'll get a Divide by Zero exception from Texture.cpp
// If pixels are flipped we must invert the Y axis
if (texture->m_pixelsFlipped)
{
matrix[5] = -matrix[5];
//On the next line
matrix[13] = static_cast<float>(texture->m_size.y / texture->m_actualSize.y);
}
I've tried rewriting the vector to handle unique_ptr<sf::Sprite>'s, but it doesn't fix anything. What am I doing wrong?
Compiled on VS2013, SFML Dynamic.