Sign in to follow this  

Problems with SDL init

This topic is 4561 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
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
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

This topic is 4561 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this