I'm currently working on an SFML-project, which I have made some of in the past. But I'm encountering a big problem now. I've got serious performance issues. I replaced all my code with a simple Main-function which you can find on the SFML website, but the Application is lagging so hard, that it takes forever to close it again.
I've tried to clean the solution, but it doesn't help. I can't find any problems by looking at the task manager either. CPU-, GPU-, DISK-, MEMORY-usage seems to be just fine. Running some of my older Problems works fine. No laggs whatsoever.
I've added the include directory to "additional include directories", I've added the library to "additional library directories", I've linked to my Additional dependencies(e.g. sfml-audio-d.lib), I've pasted the necessary dlls in my Debug/Release folder.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
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;
}
From the information provided it is hard to say where this comes from. Since you do not have a time step in your code it probably runs at maximum FPS. I always recommend to take the time step into account when doing graphics. The time step is the time between the different frames. There are several ways to handle this. The Fix Your Timestep web page summarizes them perfectly. It is kind of a reference.
I did a quick code adaptation to give you some guidance. Code is for Linux but should work on Visual Studio as well.
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
window.setFramerateLimit(60);
// Timing
sf::Clock clock;
while (window.isOpen())
{
// Update the delta time to measure movement accurately
sf::Time dt = clock.restart();
// Convert to seconds to do the maths
float dtAsSeconds = dt.asSeconds();
// For debuging, print the time to the terminal
// It illustrates the differences
std::cout << "Time step: " << dtAsSeconds << '\n';
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}