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:
Sam Lantinga 2025-03-02 07:37:46 -08:00
parent 2c46c3d5b7
commit 1a7c206986
2 changed files with 27 additions and 1 deletions

View file

@ -46,4 +46,16 @@ typedef struct SDL_error
// Defined in SDL_thread.c
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_