Sign in to follow this  
Ariste

Possible to call SDL_INIT more than once?

Recommended Posts

So is it possible to call SDL_INIT more than once? I wouldn't be initializing the same system twice, but if I wanted to call SDL_INIT separately on each system, would that be possible? For example:
SDL_INIT(SDL_INIT_VIDEO);
SDL_INIT(SDL_INIT_AUDIO);
Would that work? Thanks.

Share this post


Link to post
Share on other sites
I believe internally SDL_Init does call SDL_InitSubsystem to initialise the systems you pass as flags but calling it twice is not a good idea. If you decide at a later point to initialise a system which wasn't initialised through SDL_Init then use SDL_InitSubsystem instead.

Share this post


Link to post
Share on other sites
You can also init more than one system at once like this (i've added error checking, as you should always check that the SDL functions which return something are successful - in this case SDL_Init() returns a negative value if there was an error)

if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) {
cout << SDL_GetError() << endl;
exit(EXIT_FAILURE)
}

// if we've reached this far SDL_Init() was successful



Share this post


Link to post
Share on other sites
Yep, I know about using the bitwise OR, but the reason I wanted to use the command more than once was that I was using it in a custom SDL initialization function. I included all the error-checking and whatnot inside the function so all I had to worry about was calling it. In order to do it right, though, I needed to call initializations of subsystems separately, which is why I was wondering if you could call SDL_Init more than once.

Share this post


Link to post
Share on other sites

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