I am currently working on loading tmx levels into my game, all is going well and i have layers being loaded textures being loaded and all the data being loaded such as level name, tile sizes etc.
The issue
Loading 1 texture for tiles is perfectly ok, but loading more than 1 the texture seems to get removed from memory (only white squares are displayed) I'm not going to include all my code as there's lot's of it but i will include a couple of snippets.
//code inside load function.
Texture texture;
texture.loadFromFile(src);
Texture *t = addTexture(texture);
loadTileSheet(twidth, theight, t);
Texture* Level::addTexture(Texture texture){
Level::textures.push_back(texture);
return & textures[textures.size() - 1];
}
I am then outputting all the information to the console of the tileset this is as follows: mem adress 1 is the texture creation and mem adress 2 is the adress in the vector.
Tileset Information: nametileset2 | src G:/C++/Workspace/test/res/tileset2.png | tWidth: 32 | tHeight32 | MemAdress 1: 0x85d028 | MemAdress 2: 0xa81848
currently this works, loading in a second texture outputs this and breaks all the first set of textures.
Tileset Information: nametileset2 | src G:/C++/Workspace/test/res/tileset2.png | tWidth: 32 | tHeight32 | MemAdress 1: 0x85d028 | MemAdress 2: 0x82522b0
I'm pretty sure this is something simple that i have over looked, and I'm pretty sure the first texture is somehow being removed from memory when the second one is created somehow.
Thanks in advance:
Jordan
addTexture(Texture texture)
gets a Texture as a copy, and then it will be copied again to the container (onpush_back()
). I would change the container (supposing it's a vector) tostd::vector<Texture*>
and rethink how to create and delete textures from there. \$\endgroup\$ – MadEqua Jul 9 '16 at 15:00