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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Azmandias

Pages: [1]
1
When you insert the texture into the map, you create a copy. The local object -- which you reference from the sprite -- is destroyed at the end of the scope.
That's what I thought, but what threw me off was the penultimate object in the vector being fine.
Out of a size object test, the fifth is the only one that is the right size after I push it into the vector, and the only one that I can get from the vector later that is the right size.  Why does it work for that one, but not the others?

2
Graphics / Sprite Texture Reference Invalidated by vector.push_back
« on: July 20, 2014, 01:22:02 am »
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.

Pages: [1]