Navigation Menu

Skip to content

Commit

Permalink
Fixed bug 3696 - SDL_ShowMessageBox displays different error from int…
Browse files Browse the repository at this point in the history
…ended

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.
  • Loading branch information
slouken committed Jul 11, 2017
1 parent 37722d0 commit cd79d8c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/SDL_error.c
Expand Up @@ -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, ...)
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cd79d8c

Please sign in to comment.