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

Author Topic: Slow event-loop when mouse is moving  (Read 1014 times)

0 Members and 1 Guest are viewing this topic.

goodboye

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Slow event-loop when mouse is moving
« on: January 09, 2020, 11:19:37 am »
Hello, upon getting a new keyboard I noticed that some of my SFML projects experienced huge slow-downs whenever I moved mouse around. I searched the forums for answers and found that it's possible that the analog capabilities of my keyboard (it's a Wooting Two analog keyboard) might make the event-loop slow due to SFML's joystick handlig. But I did not find any solution to this, only links to pages that no longer exist.

I have attached a video that illustrates my problem along with the code I used to illustrate the behaviour, I'm printing the time in ms it takes to run the event-loop.

code:
#include "SFML/Graphics.hpp"
#include <iostream>
#include <chrono>

int main() {

    typedef std::chrono::high_resolution_clock Clock;
    sf::err().rdbuf(NULL);

    sf::RenderWindow window(sf::VideoMode(1280, 720), "woof!", sf::Style::Default);
    window.setFramerateLimit(60);

    while (window.isOpen()) {
        auto t1 = Clock::now();
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
                window.close();
            }
        }
        auto t2 = Clock::now();
        std::chrono::duration<double, std::milli> fp_ms = t2 - t1;
        std::cout << fp_ms.count() << std::endl;

        window.clear();
        window.display();
    }
    return 0;
}
 

I'm using "sf::err().rdbuf(NULL);" because otherwise the terminal would be packed with "Failed to set DirectInput device axis mode: 1".
Any help would be appreciated :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Slow event-loop when mouse is moving
« Reply #1 on: January 09, 2020, 01:08:49 pm »
I assume that your event loop keeps stalling due to a broken joystick/gamepad driver, which in turn also causes the error message to be printed on the console.
I'd suggest to find the bad driver and remove it or find a non-broken one.
If that's not an option, then you could give this PR a try: https://github.com/SFML/SFML/pull/1634
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/