简体   繁体   English

SFML RenderWindow需要很长时间才能打开一个窗口

[英]SFML RenderWindow taking a long time to open a window

I know this is essentially a duplicate, but this wasn't ever answered.我知道这是本质上是重复的,但这个不是永远回答。 I'd like to mention that I have followed the tutorial for using SFML along with Visual Studio, and I'm running a 64-bit project with 64-bit SFML.我想提一下,我遵循了将 SFML 与 Visual Studio 一起使用的教程,并且我正在使用 64 位 SFML 运行一个 64 位项目。 The window loaded instantly a few times, and now consistently takes 40 seconds to open on new builds/debugs.窗口会立即加载几次,现在在新构建/调试时始终需要 40 秒才能打开。 I also have the downloading of debug symbols off.我也关闭了调试符号的下载。 My graphics drivers are up to date and my HDD is fine.我的图形驱动程序是最新的,我的硬盘很好。 This is the code:这是代码:

 #include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");//This one
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);

while (window.isOpen())
{
    sf::Event event;
    while (window.pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
            window.close();
    }

    window.clear();
    window.draw(shape);
    window.display();
}

return 0;
}

Everything runs at normal speed, except for RenderWindow, which again, takes exactly 40 seconds every time.一切都以正常速度运行,除了 RenderWindow,它每次都需要 40 秒。 Does anyone know how I could fix this?有谁知道我该如何解决这个问题? I've been having this issue for a few weeks now.我已经有这个问题几个星期了。

e: Could it be my CPU? e: 会不会是我的CPU? It's not the best but I can still run most games just fine as I have a 1050ti.这不是最好的,但我仍然可以运行大多数游戏,因为我有 1050ti。 My current CPU is an i5-2500k, although I believe I got the same issue on an A10-5800k.我目前的 CPU 是 i5-2500k,虽然我相信我在 A10-5800k 上遇到了同样的问题。

EDIT: Before you resort to the solution below, try updating your keyboards firmware!编辑:在您求助于以下解决方案之前,请尝试更新您的键盘固件! You're most likely using a Corsair keyboard, so download Corsair's iCue and update your keyboard drivers.您很可能使用的是 Corsair 键盘,因此请下载 Corsair 的iCue并更新您的键盘驱动程序。 This will most likely fix these issues.这很可能会解决这些问题。 If it didn't work, then try the following:如果它不起作用,请尝试以下操作:

Since OP didn't reply any further, I tried to find a workaround myself, as this issue still exists in 2020. This workaround requires you to compile the libraries yourself.由于OP没有进一步回复,我尝试自己寻找解决方法,因为该问题在2020年仍然存在。此解决方法需要您自己编译库。 So download the source code and change the following:所以下载源代码并更改以下内容:

  • In WindowImpl.cpp , navigate to the function WindowImp::WindowImp and comment out the whole function body.WindowImpl.cpp ,导航到函数WindowImp::WindowImp并注释掉整个函数体。
  • In WindowImpl.cpp , navigate to WindowImp::popEvent and comment out the call to processJoystickEventsWindowImpl.cpp ,导航到WindowImp::popEvent并注释掉对processJoystickEvents的调用

As long as you don't use the Joystick part of SFML this should work without issues.只要您不使用 SFML 的操纵杆部分,这应该没有问题。

An contributor on the SFML discord helped me source the issue by going through and showing me how to look through the callstack, and it turned out that the freeze was when polling for dx input, and after a little bit of experimenting we figured out my k55 keyboard was to blame. SFML discord 上的一位贡献者通过浏览并向我展示如何查看调用堆栈来帮助我找到问题的根源,结果发现冻结是在轮询 dx 输入时发生的,经过一些实验,我们找到了我的 k55键盘是罪魁祸首。 I'll try to find a fix later tonight, but in short term situations unplugging it makes everything work fine.我会在今晚晚些时候尝试找到修复方法,但在短期情况下,拔掉它会使一切正常。

I have the same keyboard (Corsair K55).我有相同的键盘(海盗船 K55)。 The problem for me was Corsair's iCue software, and quitting it entirely fixed the problem for me without having to unplug my keyboard.我的问题是 Corsair 的 iCue 软件,退出它可以完全解决我的问题,而不必拔下我的键盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM