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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jpileborg

Pages: [1]
1
Window / Re: Render and event loop in different threads?
« on: January 12, 2014, 02:24:58 pm »
I'm not quite sure but I think I have read that you have to do the rendering in the thread you created the context(renderwindow). So try to do the eventhandling in the other thread.

I tried that, and the program aborted as soon as it received an event. However the error message gave me a hint, saying that I probably had forgotten to call XInitThreads first.

After I did that, it worked fine. Both creating the window in the "main" thread and then doing the rendering in a separate thread with event handling in the main thread, and doing the opposite (window creation and rendering in the main thread, while doing event handling in a new thread).

So if anyone wants to handle event-loop and rendering in different threads, remember to call XInitThreads before opening the window (I have it as the first call in the main function).

2
Window / Render and event loop in different threads?
« on: January 12, 2014, 08:36:19 am »
I'm trying to use SFML 2.1 for a small simple project, and want to have the renderer and the event loop in different threads. However it doesn't seem to be possible, as the program either crashes (segmentation fault) or get some X11 error:

XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
      after 106 requests (106 known processed) with 0 events remaining.
 

My test program is about the simplest possible:

#include <iostream>
#include <thread>
#include <SFML/Window.hpp>

namespace
{
    void renderer(sf::Window& window)
    {
        window.setActive(true);
        while (window.isOpen())
        {
            window.display();
        }
    }
}

int main()
{
    sf::Window window(sf::VideoMode(1280, 800), "Testing",
        sf::Style::Default, sf::ContextSettings(32));

    window.setActive(false);
    std::thread render_thread{renderer, std::ref(window)};

    while (window.isOpen())
    {
        sf::Event event;
        while (window.isOpen() && window.pollEvent(event))
        {
        }
    }

    render_thread.join();
}
 

Is there a way to run the rendering and event loop from different threads using SFML 2? I tried a similarly simple program using SDL2 and it works okay.

Pages: [1]