# Possible to call SDL_INIT more than once?

## Recommended Posts

Ariste    296
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 on other sites
Koshmaar    989
Probably not, since for initializing of subsystems separetely you should use SDL_InitSubsystem.

##### Share on other sites
Spudder    385
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 on other sites
Ariste    296
Ah alright, thanks. I didn't even know SDL_InitSubSystem existed =P I'll definitely use that. Thanks.

##### Share on other sites
Will F    1069
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 on other sites
Ariste    296
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.