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

Author Topic: Dragging the window causes display to stop updating  (Read 3200 times)

0 Members and 1 Guest are viewing this topic.

ph03nix

  • Newbie
  • *
  • Posts: 4
    • View Profile
Dragging the window causes display to stop updating
« on: November 30, 2013, 07:36:37 pm »
I'm using SFML 2.1 on Windows 7 and XP.

I noticed that when I click and draw the SFML window's title bar to drag the window around, the display stops updating until I release it. Is there a way to fix this?

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile

ph03nix

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Dragging the window causes display to stop updating
« Reply #2 on: December 06, 2013, 08:27:51 pm »
Is this from a different version of SFML? It says to put GetEvent on a seperate thread, but SFML 2.1 only has pollEvent.

Either way I tried putting pollEvent on a seperate thread, but the window locks up (can't drag, minimize, close) unless it's being called on the main thread.

I have a function like this:

int pollThread(){
       
        while (window.isOpen()){

                sf::Event ev;
                while (window.pollEvent(ev)){
                        if (ev.type == sf::Event::Closed){
                                window.close();
                                return 0;
                        }
                }
        }
}

And before I have the drawing loop in the main function I do this:

sf::Thread thread(&pollThread);
thread.launch();

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10829
    • View Profile
    • development blog
    • Email
AW: Dragging the window causes display to stop updating
« Reply #3 on: December 06, 2013, 09:17:19 pm »
Yes that is SFML 1.6 code. I'm not sure, but could you try to poll the events in the thread you created the window and draw in a separate thread?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ph03nix

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: AW: Dragging the window causes display to stop updating
« Reply #4 on: December 06, 2013, 10:24:23 pm »
Yes that is SFML 1.6 code. I'm not sure, but could you try to poll the events in the thread you created the window and draw in a separate thread?

That worked. Thanks! :D

Although when I call window.create to recreate the window with a different style it crashes or malfunctions (in any of the threads)
« Last Edit: December 06, 2013, 11:08:21 pm by ph03nix »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10829
    • View Profile
    • development blog
    • Email
AW: Dragging the window causes display to stop updating
« Reply #5 on: December 07, 2013, 09:05:36 am »
Well that's probably a sync issue. Writting multi threaded applications can be quite a challenge, since you'll nees to know how to make sure that the two threads don't try to access the same data at the same time (e.g. if one is changing a varianle and the other is reading it at the same time, the result is undefined).

So before you can recreate a window, you nesd to make sure the other thread isn't in the middle of using the window either.

Personally I wouldn't bother with events in a separated thread. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ph03nix

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Dragging the window causes display to stop updating
« Reply #6 on: December 07, 2013, 04:26:53 pm »
I'm making a rhythm game where the music syncs up to the gameplay, and dragging the display causes the game to become de-synchronized. I was previously using allegro, and dragging the display did not cause the game logic to stop.
« Last Edit: December 07, 2013, 04:46:43 pm by ph03nix »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Dragging the window causes display to stop updating
« Reply #7 on: December 09, 2013, 12:24:34 pm »
You could only handle the events in another thread when you are ingame, because there I guess you won't call window.create() . And in the menu/options you handle events in the main-thread to avoid raceconditions when you change the window.


AlexAUT

 

anything