Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::RenderWindow create in one thread, display in another.  (Read 4649 times)

0 Members and 1 Guest are viewing this topic.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sf::RenderWindow create in one thread, display in another.
« on: December 14, 2010, 09:23:02 pm »
I'm having a problem and I think it has something to do with my topic. Basically I send a "start" signal to my Renderer and when it receives that signal it will create the window and launch the thread that will handle the rendering. Then in the rendering thread, so far all it does is call Display on the window. I've checked and all values are correct so it's no invalid pointers or something like that. Also debugging it showed me that the threads are running like they should.

The error message I get is "Failed to activate the window's context" when I call Display.
What am I missing?

Anyway here's concerning code:

Code: [Select]
void RendererReceiver::OnStart(const SignalBase &signal)
{
const RendererStartSignal &start = static_cast<const RendererStartSignal &>(signal);
myController.InitTarget(start.GetWindow(), start.GetMode(), start.GetTitle(), start.GetStyle(), start.GetSettings());
myController.LaunchThread();
}

void RendererController::InitTarget(sf::RenderWindow *window, const sf::VideoMode &mode, const std::string &title, const unsigned long style, const sf::ContextSettings &settings)
{
myTarget = window;
window->Create(mode, title, style, settings);
window->SetFramerateLimit(MaxFrameRate);
window->Clear();
window->Display();
}

void RendererController::Run()
{
sf::Sleep(0.1f);
while(myContinueExecutionFlag == true)
{
myReceiver->ProcessSignals();
myTarget->Display();
}
}


Forgot to say that this is with SFML2 and a thought is that in Windows a window handle or opengl context or whatever is the problem might not be capable of being shared between threads? Or me missing something important.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderWindow create in one thread, display in another.
« Reply #1 on: December 14, 2010, 10:50:21 pm »
You must call myTarget->SetActive(false) before running the thread. A window can be activated in a thread only if it's not active in another thread.
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
sf::RenderWindow create in one thread, display in another.
« Reply #2 on: December 14, 2010, 10:53:58 pm »
*applies head trauma*
Stupid stupid me. I clearly remember me while making rbSFML "Sweet, I should remember this for later!".... Apparently I didn't :D

Thanks Laurent.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio