From ef3e7b256373a15451a5564287a58b595c3451cb Mon Sep 17 00:00:00 2001 From: Alex Luccisano Date: Wed, 30 Apr 2025 09:18:32 -0400 Subject: [PATCH] libobs: Add checks to some graphics API functions A few recently introduced graphics API functions needed for Enhanced Broadcasting were marked as `GRAPHICS_IMPORT_OPTIONAL`. Add the proper checks in the wrapper to ensure they are safe on platforms that do not implement the underlying function. --- libobs/graphics/graphics.c | 40 ++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index bf9848df7..00abe2ea4 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -325,22 +325,54 @@ const char *gs_get_device_name(void) const char *gs_get_driver_version(void) { - return gs_valid("gs_get_driver_version") ? thread_graphics->exports.gpu_get_driver_version() : NULL; + graphics_t *graphics = thread_graphics; + + if (!gs_valid("gs_get_driver_version")) + return NULL; + + if (graphics->exports.gpu_get_driver_version) + return (graphics->exports.gpu_get_driver_version()); + else + return NULL; } const char *gs_get_renderer(void) { - return gs_valid("gs_get_renderer") ? thread_graphics->exports.gpu_get_renderer() : NULL; + graphics_t *graphics = thread_graphics; + + if (!gs_valid("gs_get_renderer")) + return NULL; + + if (graphics->exports.gpu_get_renderer) + return (graphics->exports.gpu_get_renderer()); + else + return NULL; } uint64_t gs_get_gpu_dmem(void) { - return gs_valid("gs_get_gpu_dmem") ? thread_graphics->exports.gpu_get_dmem() : 0; + graphics_t *graphics = thread_graphics; + + if (!gs_valid("gs_get_gpu_dmem")) + return 0; + + if (graphics->exports.gpu_get_dmem) + return (graphics->exports.gpu_get_dmem()); + else + return 0; } uint64_t gs_get_gpu_smem(void) { - return gs_valid("gs_get_gpu_smem") ? thread_graphics->exports.gpu_get_smem() : 0; + graphics_t *graphics = thread_graphics; + + if (!gs_valid("gs_get_gpu_smem")) + return 0; + + if (graphics->exports.gpu_get_smem) + return (graphics->exports.gpu_get_smem()); + else + return 0; } int gs_get_device_type(void)