src/SDL_error.c
changeset 11137 15f027d062f8
parent 10737 3406a0f8b041
child 11811 5d94cb6b24d3
     1.1 --- a/src/SDL_error.c	Mon Jul 10 17:07:19 2017 -0700
     1.2 +++ b/src/SDL_error.c	Mon Jul 10 17:16:12 2017 -0700
     1.3 @@ -49,6 +49,8 @@
     1.4  
     1.5  /* Public functions */
     1.6  
     1.7 +static char *SDL_GetErrorMsg(char *errstr, int maxlen);
     1.8 +
     1.9  int
    1.10  SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    1.11  {
    1.12 @@ -110,14 +112,19 @@
    1.13      }
    1.14      va_end(ap);
    1.15  
    1.16 -    /* If we are in debug mode, print out an error message */
    1.17 -    SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", SDL_GetError());
    1.18 -
    1.19 +    if (SDL_LogGetPriority(SDL_LOG_CATEGORY_ERROR) <= SDL_LOG_PRIORITY_DEBUG) {
    1.20 +        /* If we are in debug mode, print out an error message
    1.21 +         * Avoid stomping on the static buffer in GetError, just
    1.22 +         * in case this is called while processing a ShowMessageBox to
    1.23 +         * show an error already in that static buffer.
    1.24 +         */
    1.25 +        char errmsg[SDL_ERRBUFIZE];
    1.26 +        SDL_GetErrorMsg(errmsg, sizeof(errmsg));
    1.27 +        SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", errmsg);
    1.28 +    }
    1.29      return -1;
    1.30  }
    1.31  
    1.32 -static char *SDL_GetErrorMsg(char *errstr, int maxlen);
    1.33 -
    1.34  /* Available for backwards compatibility */
    1.35  const char *
    1.36  SDL_GetError(void)