SDL_GetError(3)

πŸ’– SDL_GetError πŸ’–

okay bestie, so this is a SDL3 function (from the SDL_error.h header, hi) and it's literally the "what just went wrong" detector for your thread. Let's get into it 🫢


✨ SYNOPSIS ✨

#include <SDL3/SDL_error.h>

const char * SDL_GetError(void);

🌸 DESCRIPTION 🌸

So here's the vibe: it's totally possible for multiple errors to happen before you even call SDL_GetError(). And when that happens? You only get the last one. Just the last one, bestie. Not a whole list, not a little recap. One error. That's it. πŸ’…

The message is only applicable when an SDL function has actually signaled an error. So like, you must check the return values of SDL function calls to figure out when it's appropriate to call SDL_GetError(). Don't just be out here vibing and calling it randomly.

🚨 Big one: you should NOT use the results of SDL_GetError() to decide if an error has occurred! Sometimes SDL will set an error string even when it's reporting success. It's giving mixed signals, fr fr.

SDL will not clear the error string for successful API calls. So you have to check return values for failure cases before you can assume the error string actually applies to you. No cap.

Error strings are set per-thread, so an error that got set in a different thread will not interfere with the current thread's operation. Every thread has its own little drama going on and they don't leak into each other. Iconic, honestly. 🧚

The returned value is a thread-local string which will remain valid until the current thread's error string is changed. So if you need that value after the next SDL API call, the caller should make a copy. Like, screenshot it before it disappears. πŸ“Έ


πŸŽ€ RETURN VALUE πŸŽ€

Returns a message with information about the specific error that occurred β€” the tea, the lore, the whole story β€” or an empty string if there hasn't been an error message set since the last call to SDL_ClearError().


πŸ¦‹ THREAD SAFETY πŸ¦‹

It is safe to call this function from any thread. Slay, go wild, every thread gets to ask. ✨


⭐ AVAILABILITY ⭐

This function is available since SDL 3.2.0. If you're on something older, sorry bestie, no error-string for you. 😭


πŸ‘‘ SEE ALSO πŸ‘‘


mwah πŸ’‹ that's the whole page! This lil' cutie comes to you from the Simple Directmedia Layer girlies, version SDL 3.4.18, dated SDL_GetError(3). Go forth and check your return values, bestie πŸ’–πŸŒΈβœ¨

πŸ“¦ where this page comes from