The code for SDL_GetErrorMsg implies that it’s supposed to be thread safe to work with, but SDL_GetError calls that with a pointer into a static char buffer. And I think that’s just a global static buffer, not a thread local buffer? I’m not a C expert, so I could be totally off base.
Basically, is the error stuff thread safe? If I send my audio processing to another thread and it causes an error, will writing that error potentially cause a data race? Can I read the error from the audio thread? Or should it somehow signal to the main thread that the main thread should go check the error and just hope that no one else has caused an error in the mean time?
I share your concern. In my multi-threaded SDL2 app I call SDL_GetError() and rely on it returning the last error that occurred in the calling thread. If it really is using a global static buffer, which would seem undesirable to say the least, I suppose it should still be safe if only one thread ever calls SDL_GetError() which I think is the case in my app.
That’s really helpful, thanks. But can I ask that the online documentation also be updated to reflect this change (preferably linked from the SDL_GetError page too)? A ‘public’ API that you have no way of discovering or even guessing that it might exist is no use if you haven’t seen this thread.