SFML community forums

Bindings - other languages => D => Topic started by: jalov on February 22, 2017, 01:10:38 pm

Title: Drawing in threads
Post by: jalov on February 22, 2017, 01:10:38 pm
dfsml 2.1

Working with DSFML has been very pleasant and fairly painless so far, but now I've hit a bit of a snag.

When I call window.display in a thread I get an error "Failed to activate the windows context". I've set window inactive in the main thread and tried to pass a window to the animation thread but that's not possible, no overloads for that.

If I dont call window display in the thread the animation still works but is somewhat irregular (probably because the call to display in the main thread and the sleep in the animation thread are not coordinated).

The documentation on Drawing from Threads says "to be done later", so I guess this simply isn't implemented yet? Any work arounds?

Title: Re: Drawing in threads
Post by: sjaustirni on February 22, 2017, 02:24:33 pm
I have no experience with DSFML, but keep in mind that in the original SFML there's an implementation inconvenience which requires you to handle the window and the events in the same thread. In addition, on OSX the thread must be the main thread. See the tutorial (https://www.sfml-dev.org/tutorials/2.4/window-window.php).
Title: Re: Drawing in threads
Post by: jalov on February 22, 2017, 02:56:29 pm
I'm not doing any event handing in the thread.

The reason I'm using a separate thread is that I dont want the app to become unreponsive during the animation. There's definitely a possibility to pass a RenderWindow to a thread in SFML. See bottom of page.
http://www.sfml-dev.org/tutorials/2.4/graphics-draw.php (http://www.sfml-dev.org/tutorials/2.4/graphics-draw.php)

Since I dont need to process input during animation, I've decided to do the animation in the main thread after all. It seems to be working fine.