Jump to content
  • Advertisement
Sign in to follow this  
Mizipzor

Problems with SDL init

This topic is 4771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I run this:
	if(!SDL_Init(SDL_INIT_VIDEO)) {
		printf("Unable to init SDL: %s", SDL_GetError());
		getch();
		return -1;
	}

Program compiles fine but when I run it I get that textline, unable to init sdl... but no error. Whats wrong? Why doesnt SDL_GetError() return anything? And what do I do about it? Thanks in advance Mizii

Share this post


Link to post
Share on other sites
Advertisement
Ummmmm. My C is rusty and my brain is nonfunctional at the moment (so I could be making an embaressing mistake), but the docs say SDL_Init() returns 0 on success, -1 on failure. You should probably ditch the ! in the if statement.

Share this post


Link to post
Share on other sites
No youre right. Sorry, that was just something I took for granted :P negative values on failure. Next time ill read the documentation better... heh

Share this post


Link to post
Share on other sites

if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
{
printf("Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}


Works fine for me. :)

Share this post


Link to post
Share on other sites
As Icefox said, you should drop the '!' in the if statement. The reason: You could use JWindebank's method, but (SDL_Init() < 0) would do the computation of the 'less than' function (not overly expensive, but not necessary) and compare the result to zero (what C/C++ if statements do), where as Icefox's version just does the comparison.

[EDIT]
There is a downside to this: the code looks like it'd be complaining if the function succeeded. ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!