Hi guys. This is probably a silly question, but I searched and couldn't find anything about it.
So I've been working on a basic game and suddenly it's started exiting with 0 imediately after starting. I did some digging with GDB and the event handler seems to be the culprit.
my Game class contains the bulk of the code
Game.h
class Game
{
//state/level getters/setters, etc
static sf::RenderWindow* window;
static sf::Event event;
static void run();
}
main.cpp
int main()
{
Game();
Game::run();
return 0;
}
Game.cpp
void Game::run()
{
while (Game::window->pollEvent(Game::event)) {
if (Game::event.type == sf::Event::Closed)
Game::window->close();
window->clear(sf::Color::White);
//state machine stuff
Game::window->display();
}
}
One frame of game logic happens, and then the event says that the window was closed, causing the program to "successfully" exit with 0.
The Game class has mostly static members, so that things can easily interact with each other. If this is bad practice, please let me know, as I'm very new to C++.
I'm on Windows 10, using Code::Blocks 17.12, and SFML is dynamically linked, if that matters.
Any reason as to why this is happening?