I've run into this problem while trying to load a texture in a thread. It works for a while, but after a few iterations the error "Failed to share the OpenGL context" pops up. After some more iterations, "An internal OpenGL call failed in Texture.cpp <n> : GL_INVALID_OPERATION, the specified operation is not allowed in the current state" is written 15 times, with n changing between 38, 45, 95, 136, 144-149, 198, 335, 336 and 498. I've narrowed down the problem to this snippet of code:
#include <iostream>
#include <SFML/Graphics.hpp>
void getMandelbrot() {
sf::Context context;
std::cout << "rendering... ";
sf::Image image;
image.create(100, 100);
sf::Texture texture;
texture.loadFromImage(image);
std::cout << "done \n";
}
int main() {
sf::RenderWindow window(sf::VideoMode(300, 300), "Test");
sf::Thread update(&getMandelbrot);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
update.launch();
}
}
The problem seems to lie in "texture.loadFromImage(image);". Removing sf::Context context doesn't change anything.