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

Author Topic: pollEvent takes too long to respond on keyRelease Event  (Read 2515 times)

0 Members and 2 Guests are viewing this topic.

nikoloz

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
pollEvent takes too long to respond on keyRelease Event
« on: March 11, 2018, 03:36:13 pm »
I have a multiplayer_game class in my game, which is responsible for playing that game between two players. After pressing the Escape button, I want to go instantly back to the choose_player window, where you can choose the game mode(singleplayer/multiplayer). To do that, I'm using this code :

        sf::Event event;

   while (window->pollEvent(event))
   {
      if ((event.type == sf::Event::KeyReleased) && (event.key.code == sf::Keyboard::Escape))
      {
         coreState.SetState(new choose_player);
      }
   }
       
       The problem is, hitting the escape button doesn't always respond (most of the time it takes me back to the choose_player mode,but  sometimes several pressing on the escape is necessary).


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: pollEvent takes too long to respond on keyRelease Event
« Reply #1 on: March 11, 2018, 06:39:21 pm »
This is not supposed to happen.

What's your OS? Can you reproduce it on other PCs? Do you have other event loops in your code? Can you reproduce the problem with a minimal code (ie. just an event loop that prints something when escape is released)?
Laurent Gomila - SFML developer

nikoloz

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: pollEvent takes too long to respond on keyRelease Event
« Reply #2 on: March 12, 2018, 03:03:48 pm »
I've got another event loop in the source.cpp file, I'll provide a code snippet here: https://codepad.co/snippet/np8kumZc#   

I copied the multiplayer_game.cpp event loop in the source.cpp main while loop to test and it worked perfect. I guess it has something to do with the fact that I'm passing a pointer to the window object in the multiplayer_game.cpp, I just don't understand why or how it affects the program.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: pollEvent takes too long to respond on keyRelease Event
« Reply #3 on: March 12, 2018, 03:14:50 pm »
It's just that events retrieved in one event loop won't be seen in the other... so you're missing events in both event loops. You should really just have one event loop, and then manage to dispatch events to whoever needs to process them.
Laurent Gomila - SFML developer

nikoloz

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: pollEvent takes too long to respond on keyRelease Event
« Reply #4 on: March 12, 2018, 03:20:29 pm »
Thank you.