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

Author Topic: Program exiting when it shouldnt [SOLVED]  (Read 2012 times)

0 Members and 1 Guest are viewing this topic.

That Martin Guy

  • Newbie
  • *
  • Posts: 27
    • View Profile
Program exiting when it shouldnt [SOLVED]
« 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
Its a bit outdated, but the program i wrote as above works.
« Last Edit: February 11, 2015, 11:38:01 am by That Martin Guy »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
AW: Program exiting when it shouldnt
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

That Martin Guy

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: AW: Program exiting when it shouldnt
« Reply #2 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!

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Program exiting when it shouldnt [SOLVED]
« Reply #3 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.

 

anything