SFML community forums

Help => General => Topic started by: That Martin Guy on February 11, 2015, 10:17:01 am

Title: Program exiting when it shouldnt [SOLVED]
Post by: That Martin Guy on February 11, 2015, 10:17:01 am
After the program has loaded all the files it needs, it exits after a while, when it should give me a red colored screen.

Game.h
#pragma once
#include "stdafx.h"

class Game
{
public:
        void start();
private:
        bool isExiting();
        void gameLoop();

        enum GameState{uninitialized, showingSplash, paused, showMenu, playing, exiting};

        GameState _gameState;
        sf::RenderWindow _mainWindow;
};

Game.cpp
#include "stdafx.h"
#include "Game.h"

void Game::start()
{
        if(_gameState != uninitialized)
        {
                return;

                _mainWindow.create(sf::VideoMode(1024, 768, 32), "Pang!");
                _gameState = playing;
        }
        while(!isExiting())
        {
                gameLoop();
        }
        _mainWindow.close();
}
bool Game::isExiting()
{
        if(_gameState == exiting)
        {
                return true;
        }
        else
        {
                return false;
        }
}
void Game::gameLoop()
{
        sf::Event currentEvent;
        while(_mainWindow.pollEvent(currentEvent))
        {
                switch(_gameState)
                {
                case playing:
                        _mainWindow.clear(sf::Color::Red);
                        _mainWindow.display();

                        if(currentEvent.type == sf::Event::Closed)
                        {
                                _gameState = exiting;
                        }
                }
        }
}

Output
'Pang!.exe': Loaded 'C:\Users\Axel\Desktop\Pang!\Debug\Pang!.exe', Symbols loaded.
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Symbols loaded.
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Program Files (x86)\SearchProtect\SearchProtect\bin\VC32Loader.dll', Cannot find or open the PDB file
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Symbols loaded (source information stripped).
'Pang!.exe': Unloaded 'C:\Program Files (x86)\SearchProtect\SearchProtect\bin\VC32Loader.dll'
'Pang!.exe': Unloaded 'C:\Windows\SysWOW64\version.dll'
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\nvoglv32.dll', Cannot find or open the PDB file
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\wintrust.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\ntmarta.dll', Symbols loaded (source information stripped).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\Wldap32.dll', Symbols loaded (source information stripped).
The thread 'Win32 Thread' (0xa78) has exited with code 0 (0x0).
'Pang!.exe': Loaded 'C:\Windows\SysWOW64\powrprof.dll', Symbols loaded (source information stripped).
'Pang!.exe': Unloaded 'C:\Windows\SysWOW64\powrprof.dll'
The thread 'Win32 Thread' (0xe98) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1c74) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1c9c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1b34) has exited with code 0 (0x0).
The program '[7812] Pang!.exe: Native' has exited with code 0 (0x0).
 

Im following this tutorial: http://www.gamefromscratch.com/page/Game-from-Scratch-CPP-Edition-Part-2.aspx (http://www.gamefromscratch.com/page/Game-from-Scratch-CPP-Edition-Part-2.aspx)
Its a bit outdated, but the program i wrote as above works.
Title: AW: Program exiting when it shouldnt
Post by: eXpl0it3r on February 11, 2015, 10:51:21 am
Since it exits with code 0, it exists cleanly. Which means some code path in your application let's it exit.

Without the complete and minimal code it's impossible to tell.

For example, if you don't initialize the uninitialized variable it might contain a random value and exit before anything ever happens.
Title: Re: AW: Program exiting when it shouldnt
Post by: That Martin Guy on February 11, 2015, 11:28:57 am
After a while of debugging, it was because of the issue that exploiter pointed out. I had forgotten to make _gameState uninitialized. Fixed this by adding this to Game.cpp:

Game::Game()
{
        _gameState = uninitialized;
}

Thankyou for saving me from my brain fart, exploiter!
Title: Re: Program exiting when it shouldnt [SOLVED]
Post by: Jesper Juhl on February 12, 2015, 07:08:03 pm
Quote
if(_gameState != uninitialized)
    {
        return;

        _mainWindow.create(sf::VideoMode(1024, 768, 32), "Pang!");
        _gameState = playing;
    }
You will never execute those two statements at the end, only ever the return statement.