CAEDRMetadata.hlg(ambientViewingEnvironment:) API crash

I am trying to use the new API CAEDRMetadata.hlg(ambientViewingEnvironment:) introduced in iOS 17.0. Since ambientViewingEnvironmentData is dynamic, I understand the edrMetaData of CAMetalLayer needs to be set on every draw call. But doing so causes CAMetalLayer to freeze and even crash.

if let pixelBuffer = image.pixelBuffer,  let aveData = pixelBuffer.attachments.propagated[kCVImageBufferAmbientViewingEnvironmentKey as String] as? Data {
            if #available(iOS 17.0, *) {
                metalLayer.edrMetadata = CAEDRMetadata.hlg(ambientViewingEnvironment: aveData)
            } else {
                // Fallback on earlier versions
            }
        }
CAEDRMetadata.hlg(ambientViewingEnvironment:) API crash
 
 
Q