From 4edb0347907a27f4d0c0ce2e60cbc70305bf6d4e Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Thu, 28 Jul 2022 19:03:52 +0200 Subject: [PATCH] libobs-opengl: Fix error message for invalid IOSurface buffers Syphon relies on global IOSurfaces which are not officially supported by macOS anymore. While the core functionality is still available, `IOSurfaceGetPixelFormat` will not return a valid pixel format. --- libobs-opengl/gl-cocoa.m | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libobs-opengl/gl-cocoa.m b/libobs-opengl/gl-cocoa.m index bf9bbac2d..c4a69d08c 100644 --- a/libobs-opengl/gl-cocoa.m +++ b/libobs-opengl/gl-cocoa.m @@ -334,7 +334,9 @@ gs_texture_t *device_texture_create_from_iosurface(gs_device_t *device, struct gs_texture_2d *tex = bzalloc(sizeof(struct gs_texture_2d)); OSType pf = IOSurfaceGetPixelFormat(ref); - if (pf != 'BGRA') + if (pf == 0) + blog(LOG_ERROR, "Invalid IOSurface Buffer"); + else if (pf != 'BGRA') blog(LOG_ERROR, "Unexpected pixel format: %d (%c%c%c%c)", pf, pf >> 24, pf >> 16, pf >> 8, pf); @@ -415,9 +417,14 @@ bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf) IOSurfaceRef ref = (IOSurfaceRef)iosurf; OSType pf = IOSurfaceGetPixelFormat(ref); - if (pf != 'BGRA') - blog(LOG_ERROR, "Unexpected pixel format: %d (%c%c%c%c)", pf, - pf >> 24, pf >> 16, pf >> 8, pf); + if (pf == 0) { + blog(LOG_ERROR, "Invalid IOSurface buffer"); + } else { + if (pf != 'BGRA') + blog(LOG_ERROR, + "Unexpected pixel format: %d (%c%c%c%c)", pf, + pf >> 24, pf >> 16, pf >> 8, pf); + } tex->width = IOSurfaceGetWidth(ref); tex->height = IOSurfaceGetHeight(ref);