Browse Source

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.
Alex Luccisano 5 months ago
parent
commit
ef3e7b2563
1 changed files with 36 additions and 4 deletions
  1. 36 4
      libobs/graphics/graphics.c

+ 36 - 4
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)