It works with a single thread anyways, as soon as start the 2nd thread (graphics) it starts to hang again, even when I dont acess the rendertexture anywhere in that thread (only Update it)
I've got my graphics loop down to clear windows, display window, loop again and it still happens.
As I understood it I can only have one OpenGL context per Thread, but multiple per Process at the same time, right?
Some code:
void Game::GraphicLoop() {
m_window.setActive(true);
while (m_running) {
/*m_lastLogicUpdateMutex.lock();
sf::Time delta = m_lastLogicUpdate.getElapsedTime();
m_lastLogicUpdateMutex.unlock();*/
sf::Color clearColor(15, 235, 165);
m_window.clear(clearColor);
/*if (m_scene) {
m_scene->draw(m_window, sf::RenderStates::Default, delta.asSeconds());
}*/
m_window.display();
}
}
void Game::LogicLoop() {
sf::Time interval = sf::seconds(1.0f / 60.0f); // 60cycles/s
//sf::Clock timer;
//timer.restart();
while (m_running) {
/*m_lastLogicUpdateMutex.lock();
m_lastLogicUpdate.restart();
m_lastLogicUpdateMutex.unlock();
sf::Event event;
while (m_window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
// TODO: implement events/callbacks
m_window.close();
m_running = false;
}
}*/
m_scene->update(interval);
/*sf::Time delta = timer.restart();
if (delta < interval) {
sf::sleep(interval - delta);
}*/
}
}
m_scene->update calls this (Commented everything except Begin out to exclude those):
//m_world->Step(interval.asSeconds(), 8, 3);
//m_mutexDebug.lock();
std::cout << "Begin" << std::endl;
m_debugDraw.Begin();
std::cout << "Begin over" << std::endl;
//m_world->DrawDebugData();
//m_debugDraw.End();
//m_mutexDebug.unlock();
//m_lightSystem.update(interval);
void Box2dDebugDraw::Begin() {
std::cout << "Begin active" << std::endl;
m_texture.setActive(true);
std::cout << "Begin active over" << std::endl;
m_texture.clear(sf::Color(0, 0, 0, 0));
std::cout << "Begin clear over" << std::endl;
}
void Box2dDebugDraw::End() {
m_texture.display();
m_texture.setActive(false);
m_isInitialized = true;
}
Hangs after Begin active over
I'm really out of ideas here, the lock up only happens on startup.
So if it starts up fine, it wont hang