Abstract SDL success/failure checks inside a compat macro

This commit is contained in:
Cameron Gutman 2025-01-30 23:36:46 -06:00
parent 3a22a01aef
commit 5290305944
8 changed files with 15 additions and 13 deletions

View File

@ -103,6 +103,8 @@ SDL_Window* SDLC_CreateWindowWithFallback(const char *title,
Uint32 optionalFlags);
void SDLC_FlushWindowEvents();
#define SDLC_SUCCESS(x) ((x) == 0)
#define SDLC_FAILURE(x) ((x) != 0)
#ifdef __cplusplus
}

View File

@ -128,7 +128,7 @@ void SystemProperties::querySdlVideoInfoInternal()
{
hasHardwareAcceleration = false;
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_VIDEO))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
SDL_GetError());
@ -188,7 +188,7 @@ void SystemProperties::refreshDisplays()
void SystemProperties::refreshDisplaysInternal()
{
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_VIDEO))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
SDL_GetError());

View File

@ -37,7 +37,7 @@ void SdlGamepadKeyNavigation::enable()
// arrival events. Additionally, there's a race condition between
// our QML objects being destroyed and SDL being deinitialized that
// this solves too.
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) failed: %s",
SDL_GetError());

View File

@ -515,7 +515,7 @@ int main(int argc, char *argv[])
// The DXVA2 renderer uses Direct3D 9Ex itself directly.
SDL_SetHint(SDL_HINT_WINDOWS_USE_D3D9EX, "1");
if (SDL_InitSubSystem(SDL_INIT_TIMER) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_TIMER))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_TIMER) failed: %s",
SDL_GetError());
@ -525,7 +525,7 @@ int main(int argc, char *argv[])
#ifdef STEAM_LINK
// Steam Link requires that we initialize video before creating our
// QGuiApplication in order to configure the framebuffer correctly.
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_VIDEO)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
SDL_GetError());

View File

@ -8,7 +8,7 @@ SdlAudioRenderer::SdlAudioRenderer()
{
SDL_assert(!SDL_WasInit(SDL_INIT_AUDIO));
if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_AUDIO))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_AUDIO) failed: %s",
SDL_GetError());

View File

@ -904,7 +904,7 @@ QString SdlInputHandler::getUnmappedGamepads()
{
QString ret;
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) failed: %s",
SDL_GetError());

View File

@ -148,7 +148,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i
// can allow mapping manager to update the mappings before GC attach
// events are generated.
SDL_assert(!SDL_WasInit(SDL_INIT_JOYSTICK));
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_JOYSTICK))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_JOYSTICK) failed: %s",
SDL_GetError());
@ -166,7 +166,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i
// We need to reinit this each time, since you only get
// an initial set of gamepad arrival events once per init.
SDL_assert(!SDL_WasInit(SDL_INIT_GAMECONTROLLER));
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) failed: %s",
SDL_GetError());
@ -174,7 +174,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i
#if !SDL_VERSION_ATLEAST(2, 0, 9)
SDL_assert(!SDL_WasInit(SDL_INIT_HAPTIC));
if (SDL_InitSubSystem(SDL_INIT_HAPTIC) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_HAPTIC))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_HAPTIC) failed: %s",
SDL_GetError());

View File

@ -606,7 +606,7 @@ bool Session::initialize()
}
#endif
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_VIDEO))) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
SDL_GetError());
@ -1282,7 +1282,7 @@ void Session::getWindowDimensions(int& x, int& y,
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
SDL_Rect displayBounds;
if (SDL_GetDisplayBounds(i, &displayBounds) == 0) {
if (SDLC_SUCCESS(SDL_GetDisplayBounds(i, &displayBounds))) {
if (displayBounds.x == displayRect.x() &&
displayBounds.y == displayRect.y()) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
@ -1307,7 +1307,7 @@ void Session::getWindowDimensions(int& x, int& y,
}
SDL_Rect usableBounds;
if (SDL_GetDisplayUsableBounds(displayIndex, &usableBounds) == 0) {
if (SDLC_SUCCESS(SDL_GetDisplayUsableBounds(displayIndex, &usableBounds))) {
// Don't use more than 80% of the display to leave room for system UI
// and ensure the target size is not odd (otherwise one of the sides
// of the image will have a one-pixel black bar next to it).