- fix ref counting on init, make sure you refcount each init calls and not just the first one
This commit is contained in:
Jørgen P. Tjernø 2013-02-25 16:52:50 -08:00
parent a3482e3ac0
commit ef5e7f5c65

View file

@ -105,11 +105,13 @@ SDL_InitSubSystem(Uint32 flags)
#endif #endif
/* Initialize the timer subsystem */ /* Initialize the timer subsystem */
if ((flags & SDL_INIT_TIMER) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_TIMER)) { if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_TIMER)) {
#if !SDL_TIMERS_DISABLED #if !SDL_TIMERS_DISABLED
if (SDL_TimerInit() < 0) { if (SDL_TimerInit() < 0) {
return (-1); return (-1);
} }
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER); SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
#else #else
SDL_SetError("SDL not built with timer support"); SDL_SetError("SDL not built with timer support");
@ -118,11 +120,13 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the video/event subsystem */ /* Initialize the video/event subsystem */
if ((flags & SDL_INIT_VIDEO) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_VIDEO)) { if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_VIDEO)) {
#if !SDL_VIDEO_DISABLED #if !SDL_VIDEO_DISABLED
if (SDL_VideoInit(NULL) < 0) { if (SDL_VideoInit(NULL) < 0) {
return (-1); return (-1);
} }
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO); SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
#else #else
SDL_SetError("SDL not built with video support"); SDL_SetError("SDL not built with video support");
@ -131,11 +135,13 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the audio subsystem */ /* Initialize the audio subsystem */
if ((flags & SDL_INIT_AUDIO) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_AUDIO)) { if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_AUDIO)) {
#if !SDL_AUDIO_DISABLED #if !SDL_AUDIO_DISABLED
if (SDL_AudioInit(NULL) < 0) { if (SDL_AudioInit(NULL) < 0) {
return (-1); return (-1);
} }
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO); SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
#else #else
SDL_SetError("SDL not built with audio support"); SDL_SetError("SDL not built with audio support");
@ -149,11 +155,13 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the joystick subsystem */ /* Initialize the joystick subsystem */
if ((flags & SDL_INIT_JOYSTICK) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_JOYSTICK)) { if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_JOYSTICK)) {
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_JoystickInit() < 0) { if (SDL_JoystickInit() < 0) {
return (-1); return (-1);
} }
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK); SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
#else #else
SDL_SetError("SDL not built with joystick support"); SDL_SetError("SDL not built with joystick support");
@ -161,11 +169,13 @@ SDL_InitSubSystem(Uint32 flags)
#endif #endif
} }
if ((flags & SDL_INIT_GAMECONTROLLER) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_GAMECONTROLLER)) { if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_GAMECONTROLLER)) {
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_GameControllerInit() < 0) { if (SDL_GameControllerInit() < 0) {
return (-1); return (-1);
} }
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER); SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
#else #else
SDL_SetError("SDL not built with joystick support"); SDL_SetError("SDL not built with joystick support");
@ -174,11 +184,13 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the haptic subsystem */ /* Initialize the haptic subsystem */
if ((flags & SDL_INIT_HAPTIC) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_HAPTIC)) { if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_HAPTIC)) {
#if !SDL_HAPTIC_DISABLED #if !SDL_HAPTIC_DISABLED
if (SDL_HapticInit() < 0) { if (SDL_HapticInit() < 0) {
return (-1); return (-1);
} }
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC); SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
#else #else
SDL_SetError("SDL not built with haptic (force feedback) support"); SDL_SetError("SDL not built with haptic (force feedback) support");