(Wasn't sure where to put this so I put the topic in General)
Hi,
In the game I am working on, I have a series of gamestates, and when a level is supposed to be loaded, a 'loading' state is set that shows and animates some graphics, while a separate thread loads the level.
More often than not, it works perfectly. However, on some occasions, when the loader finishes, the console output is flooded with GL_INVALID_OPERATION errors (related to SFML's Texture.cpp calls). So my guess is that the contexts are not sharing texture names properly. The strange part is that it isn't entirely reproducible; most of the time it works just fine and the level loads without problems, but on some seemingly random times, it will as mentioned, seemingly fail to share them.
I figure it has to be something in my multithreaded function, so here is the code in particular:
std::function<void()> f([&] () {
sf::Context context;
context.setActive(true);
if(!FileSystem::OpenDir("./levels/"))
{
glFlush();
glFinish();
context.setActive(false);
app->Error("FileSystem::OpenDir() -- Could not open dir ./levels/");
Gamestate::Notify(GAMESTATE_GOTO_MENU);
return;
}
std::string level = FileSystem::GetFileLocation("testlevel.tmx");
if(World::LoadWorld(level))
{
glFlush();
glFinish();
context.setActive(false);
Gamestate::Notify(GAMESTATE_GOTO_PLAYING);
return;
}
else
{
glFlush();
glFinish();
context.setActive(false);
app->Error("World::LoadWorld() -- Could not load level");
Gamestate::Notify(GAMESTATE_GOTO_MENU);
return;
}
});
Obviously it's a lambda function, which then gets placed into a Thread Pool that queues it up on an open thread.
The game uses the TMX Loader library, creating sf::Texture instances for tiles and such. World::LoadWorld() mostly just passes on the level to said TMX loader, and does some parsing. As can be seen from the code, the thread is definitely running because the Gamestate will not be changed until the loader has finished (or returns some error). In short, there shouldn't be anything out of the ordinary...right?
[EDIT] As I've read around a bit and see that it could be relevant, I'm running on Windows 7 Home Premium 64-bit, using SFML 2.2.