We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3696

Summary: SDL_ShowMessageBox displays different error from intended
Product: SDL Reporter: Mark Callow <libsdl.org>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: iPhone/iPod touch   
OS: Other   
Attachments: Fix to avoid stomping on existing errors

Description Mark Callow 2017-07-06 21:47:31 UTC
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.
Comment 1 Mark Callow 2017-07-07 00:20:14 UTC
Created attachment 2788 [details]
Fix to avoid stomping on existing errors

The proper fix is in the attached patch. It changes SDL_SetError to use SDL_GetErrorMsg instead of SDL_GetError.

The fix is included in the Vulkan support in bug #3591 because this bug was screwing up my error messages while I was working on that one.
Comment 2 Sam Lantinga 2017-07-11 00:16:35 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/15f027d062f8