mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-05 23:10:58 +00:00
Save and restore error messages when rolling back after failed init
Fixes https://github.com/libsdl-org/SDL/issues/12439
This commit is contained in:
parent
2c46c3d5b7
commit
1a7c206986
2 changed files with 27 additions and 1 deletions
16
src/SDL.c
16
src/SDL.c
|
@ -356,7 +356,9 @@ bool SDL_InitSubSystem(SDL_InitFlags flags)
|
||||||
SDL_IncrementSubsystemRefCount(SDL_INIT_VIDEO);
|
SDL_IncrementSubsystemRefCount(SDL_INIT_VIDEO);
|
||||||
if (!SDL_VideoInit(NULL)) {
|
if (!SDL_VideoInit(NULL)) {
|
||||||
SDL_DecrementSubsystemRefCount(SDL_INIT_VIDEO);
|
SDL_DecrementSubsystemRefCount(SDL_INIT_VIDEO);
|
||||||
|
SDL_PushError();
|
||||||
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
||||||
|
SDL_PopError();
|
||||||
goto quit_and_error;
|
goto quit_and_error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -381,7 +383,9 @@ bool SDL_InitSubSystem(SDL_InitFlags flags)
|
||||||
SDL_IncrementSubsystemRefCount(SDL_INIT_AUDIO);
|
SDL_IncrementSubsystemRefCount(SDL_INIT_AUDIO);
|
||||||
if (!SDL_InitAudio(NULL)) {
|
if (!SDL_InitAudio(NULL)) {
|
||||||
SDL_DecrementSubsystemRefCount(SDL_INIT_AUDIO);
|
SDL_DecrementSubsystemRefCount(SDL_INIT_AUDIO);
|
||||||
|
SDL_PushError();
|
||||||
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
||||||
|
SDL_PopError();
|
||||||
goto quit_and_error;
|
goto quit_and_error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -406,7 +410,9 @@ bool SDL_InitSubSystem(SDL_InitFlags flags)
|
||||||
SDL_IncrementSubsystemRefCount(SDL_INIT_JOYSTICK);
|
SDL_IncrementSubsystemRefCount(SDL_INIT_JOYSTICK);
|
||||||
if (!SDL_InitJoysticks()) {
|
if (!SDL_InitJoysticks()) {
|
||||||
SDL_DecrementSubsystemRefCount(SDL_INIT_JOYSTICK);
|
SDL_DecrementSubsystemRefCount(SDL_INIT_JOYSTICK);
|
||||||
|
SDL_PushError();
|
||||||
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
||||||
|
SDL_PopError();
|
||||||
goto quit_and_error;
|
goto quit_and_error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -430,7 +436,9 @@ bool SDL_InitSubSystem(SDL_InitFlags flags)
|
||||||
SDL_IncrementSubsystemRefCount(SDL_INIT_GAMEPAD);
|
SDL_IncrementSubsystemRefCount(SDL_INIT_GAMEPAD);
|
||||||
if (!SDL_InitGamepads()) {
|
if (!SDL_InitGamepads()) {
|
||||||
SDL_DecrementSubsystemRefCount(SDL_INIT_GAMEPAD);
|
SDL_DecrementSubsystemRefCount(SDL_INIT_GAMEPAD);
|
||||||
|
SDL_PushError();
|
||||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||||
|
SDL_PopError();
|
||||||
goto quit_and_error;
|
goto quit_and_error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -493,7 +501,9 @@ bool SDL_InitSubSystem(SDL_InitFlags flags)
|
||||||
SDL_IncrementSubsystemRefCount(SDL_INIT_CAMERA);
|
SDL_IncrementSubsystemRefCount(SDL_INIT_CAMERA);
|
||||||
if (!SDL_CameraInit(NULL)) {
|
if (!SDL_CameraInit(NULL)) {
|
||||||
SDL_DecrementSubsystemRefCount(SDL_INIT_CAMERA);
|
SDL_DecrementSubsystemRefCount(SDL_INIT_CAMERA);
|
||||||
|
SDL_PushError();
|
||||||
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
||||||
|
SDL_PopError();
|
||||||
goto quit_and_error;
|
goto quit_and_error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -511,7 +521,11 @@ bool SDL_InitSubSystem(SDL_InitFlags flags)
|
||||||
return SDL_ClearError();
|
return SDL_ClearError();
|
||||||
|
|
||||||
quit_and_error:
|
quit_and_error:
|
||||||
SDL_QuitSubSystem(flags_initialized);
|
{
|
||||||
|
SDL_PushError();
|
||||||
|
SDL_QuitSubSystem(flags_initialized);
|
||||||
|
SDL_PopError();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,4 +46,16 @@ typedef struct SDL_error
|
||||||
// Defined in SDL_thread.c
|
// Defined in SDL_thread.c
|
||||||
extern SDL_error *SDL_GetErrBuf(bool create);
|
extern SDL_error *SDL_GetErrBuf(bool create);
|
||||||
|
|
||||||
|
// Macros to save and restore error values
|
||||||
|
#define SDL_PushError() \
|
||||||
|
char *saved_error = SDL_strdup(SDL_GetError())
|
||||||
|
|
||||||
|
#define SDL_PopError() \
|
||||||
|
do { \
|
||||||
|
if (saved_error) { \
|
||||||
|
SDL_SetError("%s", saved_error); \
|
||||||
|
SDL_free(saved_error); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#endif // SDL_error_c_h_
|
#endif // SDL_error_c_h_
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue