Fixed cleaning up dependent subsystems if initialization fails

This commit is contained in:
Sam Lantinga 2024-09-15 11:40:31 -07:00
parent 97d40b9218
commit 5b5b1a8926
1 changed files with 5 additions and 0 deletions

View File

@ -333,6 +333,7 @@ SDL_bool SDL_InitSubSystem(SDL_InitFlags flags)
SDL_IncrementSubsystemRefCount(SDL_INIT_VIDEO);
if (!SDL_VideoInit(NULL)) {
SDL_DecrementSubsystemRefCount(SDL_INIT_VIDEO);
SDL_QuitSubSystem(SDL_INIT_EVENTS);
goto quit_and_error;
}
} else {
@ -357,6 +358,7 @@ SDL_bool SDL_InitSubSystem(SDL_InitFlags flags)
SDL_IncrementSubsystemRefCount(SDL_INIT_AUDIO);
if (!SDL_InitAudio(NULL)) {
SDL_DecrementSubsystemRefCount(SDL_INIT_AUDIO);
SDL_QuitSubSystem(SDL_INIT_EVENTS);
goto quit_and_error;
}
} else {
@ -381,6 +383,7 @@ SDL_bool SDL_InitSubSystem(SDL_InitFlags flags)
SDL_IncrementSubsystemRefCount(SDL_INIT_JOYSTICK);
if (!SDL_InitJoysticks()) {
SDL_DecrementSubsystemRefCount(SDL_INIT_JOYSTICK);
SDL_QuitSubSystem(SDL_INIT_EVENTS);
goto quit_and_error;
}
} else {
@ -404,6 +407,7 @@ SDL_bool SDL_InitSubSystem(SDL_InitFlags flags)
SDL_IncrementSubsystemRefCount(SDL_INIT_GAMEPAD);
if (!SDL_InitGamepads()) {
SDL_DecrementSubsystemRefCount(SDL_INIT_GAMEPAD);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
goto quit_and_error;
}
} else {
@ -466,6 +470,7 @@ SDL_bool SDL_InitSubSystem(SDL_InitFlags flags)
SDL_IncrementSubsystemRefCount(SDL_INIT_CAMERA);
if (!SDL_CameraInit(NULL)) {
SDL_DecrementSubsystemRefCount(SDL_INIT_CAMERA);
SDL_QuitSubSystem(SDL_INIT_EVENTS);
goto quit_and_error;
}
} else {