{"record":{"id":"dcda65d388ca3cbe","repo":"AvaloniaUI/Avalonia","slug":"unable-to-export-iosurfaceref-dcda65","errorCode":null,"errorMessage":"Unable to export IOSurfaceRef","messagePattern":"Unable to export IOSurfaceRef","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"samples/GpuInterop/VulkanDemo/VulkanTimelineSemaphore.cs","lineNumber":62,"sourceCode":"\n    \n    public unsafe IntPtr ExportSharedEvent()\n    {\n        if (!_resources.Api.TryGetDeviceExtension<ExtMetalObjects>(_resources.Instance, _resources.Device, out var ext))\n            throw new InvalidOperationException();\n        var eventExport = new ExportMetalSharedEventInfoEXT()\n        {\n            SType = StructureType.ExportMetalSharedEventInfoExt,\n            Semaphore = Handle,\n        };\n        var export = new ExportMetalObjectsInfoEXT()\n        {\n            SType = StructureType.ExportMetalObjectsInfoExt,\n            PNext = &eventExport\n        };\n        ext.ExportMetalObjects(_resources.Device, ref export);\n        if (eventExport.MtlSharedEvent == IntPtr.Zero)\n            throw new Exception(\"Unable to export IOSurfaceRef\");\n        return eventExport.MtlSharedEvent;\n    }\n    public IPlatformHandle Export()\n    {\n        if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))\n            return new PlatformHandle(ExportSharedEvent(),\n                KnownPlatformGraphicsExternalSemaphoreHandleTypes.MetalSharedEvent);\n        throw new PlatformNotSupportedException();\n    }\n}\n","sourceCodeStart":44,"sourceCodeEnd":73,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/samples/GpuInterop/VulkanDemo/VulkanTimelineSemaphore.cs#L44-L73","documentation":"On macOS the VulkanTimelineSemaphore exports a Metal shared event via VK_EXT_metal_objects and checks eventExport.MtlSharedEvent; if IntPtr.Zero it throws. Note the message says 'IOSurfaceRef' — that is a copy-paste bug (this path exports an MTLSharedEvent, not an IOSurface). A zero event means the Metal-objects export failed for the semaphore.","triggerScenarios":"Calling Export() on macOS for a timeline semaphore whose VkSemaphore was not created with the Metal shared-event export chain (ExportMetalObjectUsageInfoEXT + VkExportMetalSharedEventInfoEXT), or running without VK_EXT_metal_objects.","commonSituations":"Old MoltenVK without semaphore export; semaphore created without VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_MTL_SYNC_BIT_MVT; device/instance missing VK_EXT_metal_objects.","solutions":["Enable VK_EXT_metal_objects and update MoltenVK to a version supporting shared-event export.","Create the timeline semaphore with VkExportMetalObjectCreateInfoInfoEXT (shared-event) in the pNext chain.","Also fix the misleading message to say 'MTLSharedEvent' instead of 'IOSurfaceRef'.","If export is unsupported on this macOS/GPU, fall back to CPU-side timeline emulation."],"exampleFix":"// before\nif (eventExport.MtlSharedEvent == IntPtr.Zero)\n    throw new Exception(\"Unable to export IOSurfaceRef\");\n\n// after (correct message + extension check)\nif (eventExport.MtlSharedEvent == IntPtr.Zero)\n    throw new InvalidOperationException(\"Unable to export MTLSharedEvent; the semaphore was not created with a Metal shared-event export chain.\");","handlingStrategy":"validation","validationCode":"// verify the Metal-objects extension is enabled before exporting\nif (!OperatingSystem.IsOSPlatform(OSPlatform.OSX) || !HasExtension(VkExt.MetalObjects))\n    return null;","typeGuard":"static bool CanExportSharedEvent(VkDevice dev, ISet<string> ext) =>\n    RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ext.Contains(VK_EXT_METAL_OBJECTS);","tryCatchPattern":"try { var h = semaphore.Export(); }\ncatch (Exception ex) when (ex.Message.Contains(\"IOSurfaceRef\")) // misleading message — actually MTLSharedEvent\n{ _logger.LogWarning(\"Metal shared-event export unavailable.\"); }","preventionTips":["Enable VK_EXT_metal_objects on macOS.","Create the semaphore with the Metal shared-event export chain.","Fix the copy-paste message to read 'MTLSharedEvent'."],"tags":["vulkan","macos","metal","semaphore","external-semaphore","sample","message-bug"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}