问题
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. The window loaded instantly a few times, and now consistently takes 40 seconds to open on new builds/debugs. 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. 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? It's not the best but I can still run most games just fine as I have a 1050ti. My current CPU is an i5-2500k, although I believe I got the same issue on an A10-5800k.
回答1:
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. I'll try to find a fix later tonight, but in short term situations unplugging it makes everything work fine.
来源:https://stackoverflow.com/questions/53017551/sfml-renderwindow-taking-a-long-time-to-open-a-window