This is my first time using SFML and while I was trying to make a game I noticed that whenever I ran the program, everything on my computer would start lagging. I opened the Task manager and it said that the program was using a lot of the performance. I have reproduced the bug so that it's easier to read the code.
I know the problem is in the the update function because when I comment out it's call, it doesn't cause the lag.
Here is the code
#include "SFML/Graphics.hpp"
class Game
{
private:
sf::RenderWindow* window;
public:
Game()
: window{ new sf::RenderWindow(sf::VideoMode(500, 500), "Game") }
{
}
~Game()
{
delete window;
}
void handleInputs()
{
sf::Event event;
while (window->pollEvent(event))
{
if (event.type == sf::Event::Closed)
window->close();
}
}
void update()
{
window->clear();
window->display();
}
void run()
{
while (window->isOpen())
{
handleInputs();
update();
}
}
};
int main()
{
Game game;
game.run();
return 0;
}