• Advertisement
Sign in to follow this  

Possible to call SDL_INIT more than once?

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

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
Advertisement
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
Ah alright, thanks. I didn't even know SDL_InitSubSystem existed =P I'll definitely use that. Thanks.

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
Sign in to follow this  

  • Advertisement