Is RenderImage supposed to be a forever lasting variable like RenderWindow?
Neither of them is. They are supposed to be destroyed (manually or automatically) as soon as they aren't used anymore.
Edit: So, using dynamic memory (which I do not like) to avoid the destructors
Not calling destructors is not really a solution, since it leads to memory/resource leaks. If the destructor really crashes if you are using the class correctly, then it is likely to be a bug in SFML.
Do you have a minimal code reproducing this problem?
Why can't I add RenderImage to a container?
This is how I'm doing it right now
When I say groupedTile I refer to the RenderImage, that is simply a group of tiles. startingX is the id, for example, for a 512x512 block, we copy from tile 0 (startingX), 0 (startingY) to 32 (endingX),32 (endingY)
void Map::getGroupedTiles(int startingX, int endingX, int startingY, int endingY)
{
sf::RenderImage *renderImage = new sf::RenderImage();
if (!renderImage->Create(TILES_HORIZONTAL_RENDERIMAGE*TILE_WIDTH, TILES_VERTICAL_RENDERIMAGE*TILE_HEIGHT))
{
return; // failed
}
sf::Image *tileset = gImageManager.getResource("world.png");
for (int y=startingY; y<endingY; y++)
{
for (int x=startingX; x<endingX; x++)
{
sf::Sprite sprite;
sprite.SetImage(*tileset);
sprite.SetPosition((x-startingX)*TILE_WIDTH, (y-startingY)*TILE_HEIGHT);
sprite.SetSubRect(tilesRects[mapTiles[y][x]]);
renderImage->Draw(sprite);
}
}
renderImage->Display();
sf::Sprite sprite;
sprite.SetImage(renderImage->GetImage());
sprite.SetPosition(startingX*TILE_WIDTH, startingY*TILE_HEIGHT);
map.push_back(sprite);
}
If you switch from dynamic to "normal" memory, the program will crash as soon as it leaves the function.
I suppose I'm doing this the wrong way?