Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Program immediately exiting with 0  (Read 913 times)

0 Members and 1 Guest are viewing this topic.

fgn_j

  • Newbie
  • *
  • Posts: 2
    • View Profile
Program immediately exiting with 0
« on: May 29, 2019, 04:51:46 am »
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?

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Program immediately exiting with 0
« Reply #1 on: May 29, 2019, 05:58:27 am »
You don't have a basic main loop to keep the window open, you only have an event loop.

Take a look at the basic code example in the tutorial: https://www.sfml-dev.org/tutorials/2.5/start-cb.php

fgn_j

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Program immediately exiting with 0
« Reply #2 on: May 29, 2019, 06:12:51 am »
You don't have a basic main loop to keep the window open, you only have an event loop.

Take a look at the basic code example in the tutorial: https://www.sfml-dev.org/tutorials/2.5/start-cb.php

Geez...I knew it had to be something simple  ::)

Thank you.