Hello everyone,
I encounter a weird problem when using two RenderWindows in different threads.
I'm not sure how to explain it correctly, so I will go throw it step by step.
When I boot my application a DLL (Prototari.dll) will be loaded, which is using the SFML 2.5.1 - it creates a window and loads a texture to use - but it does not render yet!
After this a second DLL (SplashScreen.dll) is loaded which will also use the SFML 2.5.1. to display a SplashScreen. While the Prototari-RenderWindow was created by the MainThread, the SplashScreen-RenderWindow will be created in a new Thread. Then, the SplashScreen-RenderWindow will run its event loop and render an image for like 2 seconds. Then the window will be closed, the thread will terminated and the SplashScreen.dll gets unloaded.
NOW the Prototari-RenderWindow starts rendering. After hitting "Enter" a new thread will load Textures, but this will fail with the message "Failed to activate OpenGL context" because the "handle is invalid".
When I dont execute the SplashScreen, everything will work. If I keep the SplashScreen active while the Prototari Window starts rendering, it will crash.
I then created a new DLL which will just open a RenderWindow (instead of using Prototari) and then close it after the SplashScreen is done.
Now I will get this message when the destructor of the RenderWindow was called.
So.... What might be the problem?
Edit: Turns out I mistook the order or the different RenderWindows. The SplashScreen-RenderWindow will be the first one, then the Prototari-RenderWindow is created.
Solution:
So.... I tried something different now, since the order for the 2 RenderWindows was:
1.) Creation in Non-MainThread
2.) Creation in MainThread
I decided to swap the order - now it is working! Yeah!
But I wonder: Why? Is it important that the first RenderWindow was created by the MainThread?