Hello.
I got a small problem and i am kind of clueless about this because it should normally not be possible,
I have a chunk class which contains 3 textures and 3 sprites.
On chunk.update() i load the files from my website and put then into the texture like this
sf::Http http;
http.setHost("http://bla.de/");
sf::Http::Request request;
request.setMethod(sf::Http::Request::Get);
request.setUri("images/"+Bg);
request.setHttpVersion(1, 1); // HTTP 1.1
sf::Http::Response response = http.sendRequest(request);
std::string body = response.getBody();
BgTexture.loadFromMemory(body.data(),body.size());
BgSprite.setTexture(BgTexture);
Now i created 4 testchunks
chunk Chunk1("rpgbg_0","rpggraphics_0","rpgcolli_0",1);
chunk Chunk2("rpgbg_0","rpggraphics_0","rpgcolli_0",2);
chunk Chunk3("rpgbg_0","rpggraphics_0","rpgcolli_0",3);
chunk Chunk4("rpgbg_0","rpggraphics_0","rpgcolli_0",4);
And i have a pointer which allways points to the chunk, which has to be drawn:
chunk* MainChunk = &Chunk1;
Everything nice so far, i switch stuff with hotkeys
if ( AreaSwapClock.getElapsedTime().asSeconds() > 1.F)
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num1))
{
OldMainChunk = MainChunk;
MainChunk = &Chunk1;
std::cout << "test";
ChunkRenderThread.launch();
AreaSwapClock.restart();
}
}
And everything works. Pls do not ask why i do it how i do it, it´s necesary.
Anyways the update happens in a thread , which does this function and closes
void RenderChunks()
{
loadscreen = true;
MainChunk->update();
std::cout << "thread"<< std::endl;
loadscreen = false;
}
Well now the problem:As more i switch the area as more memory gets allocated , obviously this happens but now what makes me really sick atm:
I tried a LOT of methods to stop this, at example i have put all chunk´s in a vector and if i change a chunk i first clear the vector, set him up from new and then update the chunk, so the old chunk objekt MUST be deleted and the memory goes free.
Well the ram did not care and as more i switched areas as more got allocated.
Then i tried to make a terminate function and filled the textures and spirtes with a clear dummy sprite and texture, so they take MINIMAL memory.
Well the memory usage was again going higher as more i swap and did not care.
I even tried to call manually destructors for the stuff, which i should not do, just fore testing, nothing changed.
The only possible way i see is that something with MainTexture.loadFromMemory(body.data(),body.size()); goes in Sfml wrong and the used memory never gets deleted, even if the object which should contain it does not exist anymore.
Or do you have a other explanation?