OK, I'm not having a problem per se, but something is going on in my code I can't explain. I'm writing a simple game engine with SFML and Box2D, and in my gameloop I have this line of code:
Now, when I run this, nothing is displayed. However, if I change it to this:
1 2 3
sf::Sprite Sprite;
Sprite.setTexture(textureManager.get(1));
sf::Texture tex = textureManager.get(1); //I originally just added this to print out size-info to the console
it does draw! Anyone know what's going on here? TextureManager is just a class with a vector for storing textures, and the get function simply does return textures.at(i);
is textureManager.get() returning a reference to a texture? Or a copy of one? If it returns a copy, the texture is deleted before the sprite can be drawn -- sf::Sprite does not store textures; it stores addresses to textures.
EDIT:
I can't explain why the texture is drawing in the second version of your code either. If everything is as you describe then it shouldn't be. Maybe someone else could shed some light on that.
sf::Sprite Sprite;
Sprite.setTexture(textureManager.get(1));
sf::Texture tex = textureManager.get(1); //I originally just added this to print out size-info to the console
I suspect tex occupies the same position in memory that the temp returned by the first textureManager.get(1) did before it was destroyed, and the code works by happenstance.