Skip to content

SDL3 API functions made fallible #14223

@rom1v

Description

@rom1v

Many functions which returned void in SDL2 now return bool in SDL3.

  • SDL_GetWindowSize()
  • SDL_GetWindowPosition()
  • SDL_RenderPresent()

This means that the caller should check the result. This may have a lot of consequences downstream: client functions which were infallible should now be made fallible, and the error should be handled:

true on success or false on failure; call SDL_GetError() for more information.

But when looking at the SDL source code, it turns out that they may only return false due to CHECK_XXX_MAGIC:

CHECK_WINDOW_MAGIC(window, false);

SDL/src/video/SDL_video.c

Lines 159 to 178 in 5dab2c7

#define CHECK_WINDOW_MAGIC(window, result) \
CHECK_PARAM(!_this) { \
SDL_UninitializedVideo(); \
return result; \
} \
CHECK_PARAM(!SDL_ObjectValid(window, SDL_OBJECT_TYPE_WINDOW)) { \
SDL_SetError("Invalid window"); \
return result; \
}
#define CHECK_DISPLAY_MAGIC(display, result) \
CHECK_PARAM(!display) { \
return result; \
} \
#define CHECK_WINDOW_NOT_POPUP(window, result) \
CHECK_PARAM(SDL_WINDOW_IS_POPUP(window)) { \
SDL_SetError("Operation invalid on popup windows"); \
return result; \
}

Therefore, currently, this bool only reports programming errors (for example the client calling display with a NULL display), so they should really be assertions, not errors to be handled by the caller (so the functions should still return void).

Note that the opposite change was made for SDL_LockMutex(), which were fallible in SDL2 but infallible in SDL3 (899eb0d) (which is a good thing).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions