Welcome, Guest. Please login or register.

Author Topic: Drawing in threads  (Read 98 times)

0 Members and 1 Guest are viewing this topic.

jalov

  • Newbie
  • *
  • Posts: 6
    • View Profile
Drawing in threads
« on: February 22, 2017, 12: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?


sjaustirni

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: Drawing in threads
« Reply #1 on: February 22, 2017, 01: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.

jalov

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Drawing in threads
« Reply #2 on: February 22, 2017, 01: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

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.