I have a similar problem. My implementation of an image manager uses a std::map to ensure resources aren't loaded twice:
std::map<std::string, sf::Image> g_Image;
void CEntity::SetImage(const std::string &filename) {
std::map<std::string, sf::Image>::iterator it = g_Image.find(filename);
if (it == g_Image.end()) {
sf::Image image;
image.LoadFromFile(filename);
it = g_Image.insert(it, std::pair<std::string, sf::Image>(filename, image));
}
m_Sprite.SetImage(it->second);
}
The code works as intended when all entity objects are created before the sf::RenderWindow. However, I hope to create entity objects while in the main loop of my application (after the window has been created). The problem with that is SFML is unloading before the sf::Image destructors are executed. Can anyone tell me how to work around this? Thanks in advance!
Full source code available
here.