Fixed bug 3696 - SDL_ShowMessageBox displays different error from intended

Mark Callow

SDL_ShowMessageBox calls SDL_CaptureMouse which, in the UIKit driver, raises a ?That operation is not supported? error, overwriting the SDL error that an application may be trying to report.

This is because UIKit SDL_CaptureMouse returns SDL_Unsupported() which ends up calling SDL_SetError() which has the following code:

    /* If we are in debug mode, print out an error message */
    SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", SDL_GetError());

The SDL_GetError call here overwrites the static buffer?..

Although an application can avoid this by using SDL_GetErrorMsg(char* errstr,  int maxlen) to avoid the static buffer, SDL should be fixed.

The fix is simple. In SDL_SetError change

    SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", SDL_GetError());

to

    SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", error);

where error is the pointer to the buffer where it assembled the message.
This commit is contained in:
Sam Lantinga 2017-07-10 17:16:12 -07:00
parent 37722d01a8
commit cd79d8ccec
1 changed files with 12 additions and 5 deletions

View File

@ -49,6 +49,8 @@ SDL_LookupString(const char *key)
/* Public functions */
static char *SDL_GetErrorMsg(char *errstr, int maxlen);
int
SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
@ -110,14 +112,19 @@ SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
}
va_end(ap);
/* If we are in debug mode, print out an error message */
SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", SDL_GetError());
if (SDL_LogGetPriority(SDL_LOG_CATEGORY_ERROR) <= SDL_LOG_PRIORITY_DEBUG) {
/* If we are in debug mode, print out an error message
* Avoid stomping on the static buffer in GetError, just
* in case this is called while processing a ShowMessageBox to
* show an error already in that static buffer.
*/
char errmsg[SDL_ERRBUFIZE];
SDL_GetErrorMsg(errmsg, sizeof(errmsg));
SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", errmsg);
}
return -1;
}
static char *SDL_GetErrorMsg(char *errstr, int maxlen);
/* Available for backwards compatibility */
const char *
SDL_GetError(void)