From 6c0b1550fd8d3654999f190d5b289152e710ddd4 Mon Sep 17 00:00:00 2001 From: Acaki Date: Thu, 28 Aug 2025 13:22:16 +0800 Subject: [PATCH] fix: crash when host is on hdr but client is not on Metal lower iOS versions --- VoidLink/Metal/MetalVideoRenderer.m | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/VoidLink/Metal/MetalVideoRenderer.m b/VoidLink/Metal/MetalVideoRenderer.m index 2bf482eb..8fe8868a 100644 --- a/VoidLink/Metal/MetalVideoRenderer.m +++ b/VoidLink/Metal/MetalVideoRenderer.m @@ -404,11 +404,22 @@ CFStringRef __currentColorSpace; } else { newColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_2020); } - newPixelFormat = MTLPixelFormatBGR10A2Unorm; + // Only use BGR10A2Unorm if HDR is enabled and the initial format supports it + if (_hdrEnabled && _colorPixelFormat == MTLPixelFormatBGR10A2Unorm) { + newPixelFormat = MTLPixelFormatBGR10A2Unorm; + } else { + newPixelFormat = MTLPixelFormatBGRA8Unorm; + } } else { // SDR 2020, I'm not sure it's possible to stream this though newColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_2020); - newPixelFormat = MTLPixelFormatBGR10A2Unorm; + // For SDR content, respect the initially configured pixel format + // Don't force BGR10A2Unorm unless it was configured initially + if (_hdrEnabled && _colorPixelFormat == MTLPixelFormatBGR10A2Unorm) { + newPixelFormat = MTLPixelFormatBGR10A2Unorm; + } else { + newPixelFormat = MTLPixelFormatBGRA8Unorm; + } } if (isHDR) { paramBuffer.cscParams = (fullRange ? k_CscParams_Bt2020Full_10bit : k_CscParams_Bt2020Lim_10bit);