Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Game instantly quits.

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 Dennisvb   Members   

160
Like
0Likes
Like

Posted 03 March 2013 - 08:43 AM

This is my Game.cpp file:

#include "Game.h"

bool quit = false;

// Starts the game
void Game::Start() {

	if ( Game::Init() == 1 ) {
			std::cout << SDL_GetError();
			quit = true;
		}
	
	while( !quit ) {
		if ( Game::Update() == 1 ) {
			std::cout << SDL_GetError();
			quit = true;
		}

		if ( Game::Draw() == 1 ) {
			std::cout << SDL_GetError();
			quit = true;
		}
	}

	SDL_Quit();
}

int Game::Init() {
	SDL_Init( SDL_INIT_EVERYTHING );

	return 0;
}

int Game::Update() {

	while (SDL_PollEvent( &event ) ) {
		if ( event.type == SDL_QUIT ) {
			quit = true;
		}
	}

	return 0;
}

int Game::Draw() {

	return 0;
}

 

Game::Start(); is called from main.cpp, but it quits instantly now. I hope somebody can help!

Thanks.



#2 DeafTV   Members   

1699
Like
1Likes
Like

Posted 03 March 2013 - 11:58 AM

I would have the start function initialize the library and an end function to close the library. I would also have a separate function for your main loop to call Update, Draw, etc.

 

I would also have the bool quit as a member variable to allow for more "dynamic" changing.  In my current project, the core class, GameEngine, is set up as a singleton with the bool quit as a static.  Then my main function calls are called in main within my main loop.

 

Just some design ideas as you progress further.  Cleverly placed print statements also help in debugging something like this wink.png

 

Edit: Forgot to mention that your init(), update(), and draw() functions only return 0 and not 1 which is what your if tests for.


Edited by DeafTV, 03 March 2013 - 12:04 PM.

Fly Safe 7o


#3 Khatharr   Members   

8722
Like
0Likes
Like

Posted 04 March 2013 - 02:41 AM

This is a good opportunity for you to get familiar with your IDE's debugger. A debugger can find problems like this very quickly. Just set a breakpoint at the beginning of Game::Start() and keep stepping forward until you see something go wrong.

DeafTV, on 03 Mar 2013 - 10:06, said:
Edit: Forgot to mention that your init(), update(), and draw() functions only return 0 and not 1 which is what your if tests for.

I'd assume that he'd return 1 on failure, but does not yet have failure cases coded, or else has stripped some content in order to ask his question.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#4 ultramailman   Prime Members   

1720
Like
0Likes
Like

Posted 04 March 2013 - 03:07 AM

Try rebuilding, it might magickally fix the problem. Make sure the dlls are in the same folder as the executable too.



#5 Dennisvb   Members   

160
Like
0Likes
Like

Posted 04 March 2013 - 11:12 AM

Turns out the variable quit did not initialize properly, so it got a random value which was always true, because only 0 is false I think.

#6 ultramailman   Prime Members   

1720
Like
0Likes
Like

Posted 04 March 2013 - 11:31 AM

How? In your code, it is declared and initialized to false on the same line.

 

Personally, I use a variable called "running" instead, so the game loop ends when !running.



#7 Khatharr   Members   

8722
Like
0Likes
Like

Posted 05 March 2013 - 11:56 PM

Just a shot in the dark, but could you post the contents of "Game.h"? I'm wondering if there's more than one 'quit' rolling around here.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.