{"record":{"id":"a43465293424dbb7","repo":"stride3d/stride","slug":"avassetreader-startreading-failed-err-null-err","errorCode":null,"errorMessage":"AVAssetReader.StartReading failed: {(err != null ? err.LocalizedDescription : \"unknown\")}","messagePattern":"AVAssetReader\\.StartReading failed: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Video/Backends/AVFoundationVideoBackend.cs","lineNumber":289,"sourceCode":"        // Ask the reader to deliver decoded BGRA pixel buffers backed by IOSurface. BGRA is the\n        // VideoToolbox native output format for H.264/HEVC SDR content — picking it avoids an\n        // internal NV12→RGB conversion. The IOSurface is imported as a VkImage in UploadFrameToTarget.\n        var settings = new NSMutableDictionary\n        {\n            [CVPixelBuffer.PixelFormatTypeKey] = NSNumber.FromInt32((int)CVPixelFormatType.CV32BGRA),\n            [CVPixelBuffer.IOSurfacePropertiesKey] = new NSDictionary(),\n        };\n        videoOutput = new AVAssetReaderTrackOutput(videoTrack, settings)\n        {\n            // The default of true caches output buffers via the track output's internal pool which\n            // is what we want — keeps each frame available until we Dispose() it.\n            AlwaysCopiesSampleData = false,\n        };\n        reader.AddOutput(videoOutput);\n        if (!reader.StartReading())\n        {\n            var err = reader.Error;\n            throw new InvalidOperationException(\n                $\"AVAssetReader.StartReading failed: {(err != null ? err.LocalizedDescription : \"unknown\")}\");\n        }\n    }\n\n    private void DisposeReader()\n    {\n        videoOutput?.Dispose();\n        videoOutput = null;\n        reader?.Dispose();\n        reader = null;\n    }\n\n    private void UploadFrameToTarget(CVPixelBuffer pixelBuffer)\n    {\n        var target = Instance.VideoComponent.Target;\n        if (target == null)\n            return;\n","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Video/Backends/AVFoundationVideoBackend.cs#L271-L307","documentation":"The AVAssetReader was created successfully but StartReading() returned false, meaning the reader could not begin producing samples; reader.Error supplies the underlying NSError. This happens after output configuration, so the failure is in starting the read pipeline.","triggerScenarios":"StartReading fails due to an invalid output settings combination (e.g. pixel format unsupported on device), asset becoming invalid after creation, time range settings conflicting with the asset, or resource exhaustion.","commonSituations":"Requesting a pixel format not supported on the target iOS device/simulator; seeking to a startTime beyond the asset duration producing an invalid time range; playing DRM-protected or corrupted assets; memory pressure on device.","solutions":["Read the appended err.LocalizedDescription for the concrete cause","Validate startTime is within the asset duration before CreateReader","Simplify outputSettings (use kCVPixelFormatType32BGRA or device-preferred formats)","Verify the asset is playable: check asset.Playable / tracks non-empty","Test on a physical device vs simulator — some decoders behave differently"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (startTime > asset.Duration) startTime = asset.Duration;\n// and confirm asset has a video track:\nvar tracks = asset.TracksWithMediaType(AVMediaType.Video, out _);\nif (tracks.Length == 0) throw new InvalidOperationException(\"no video track\");","typeGuard":null,"tryCatchPattern":"try { backend.Initialize(url, start, len); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"StartReading failed\"))\n{ /* retry with default output settings or clamp startTime */ }","preventionTips":["Clamp seek/start times to asset duration","Use widely supported pixel formats in output settings","Test on real devices; simulator decoders differ"],"tags":["ios","avfoundation","avassetreader","video"],"backgroundTag":"api-error-response","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}