I am making a small game, for now I just want to draw a sprite on the screen. I've used SFML before and have never gotten this exception. It only happens, when I close the window.
Here's my code:
main.cpp
#include <iostream>
#include "Game.hpp"
int main()
{
Game game;
game.run();
return 0;
}
Game.hpp
#pragma once
#include <SFML/Graphics.hpp>
class Game
{
public:
Game();
void run();
private:
void processEvents();
void update();
void render();
sf::RenderWindow window;
sf::Texture texture;
sf::Sprite player;
};
Game.cpp
#include <iostream>
#include "Game.hpp"
Game::Game()
:window(sf::VideoMode(816, 624), "SFML Application")
{
if (!texture.loadFromFile("rainer.png")) {
std::cout << "Failed to load texture" << std::endl;
}
player.setTexture(texture);
}
void Game::run()
{
while (window.isOpen())
{
processEvents();
update();
render();
}
}
void Game::processEvents()
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
}
void Game::update()
{
}
void Game::render()
{
window.clear();
// does it always need to draw something??
window.draw(player);
window.display();
}