{"record":{"id":"47680315bde9e711","repo":"stride3d/stride","slug":"could-not-find-underlying-cpu-buffer-data-and-no-command","errorCode":null,"errorMessage":"Could not find underlying CPU buffer data and no command list was given to extract them from GPU","messagePattern":"Could not find underlying CPU buffer data and no command list was given to extract them from GPU","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Extensions/IndexExtensions.cs","lineNumber":23,"sourceCode":"using System.Linq;\nusing Stride.Core;\nusing Stride.Graphics;\nusing Stride.Graphics.Data;\nusing Stride.Rendering;\nusing Buffer = Stride.Graphics.Buffer;\n\nnamespace Stride.Extensions\n{\n    public static class IndexExtensions\n    {\n        private static byte[] GetDataSafe(this Buffer buffer, CommandList commandList = null)\n        {\n            var data = buffer.GetSerializationData();\n            if (data != null)\n                return data.Content;\n\n            if (commandList == null)\n                throw new InvalidOperationException(\"Could not find underlying CPU buffer data and no command list was given to extract them from GPU\");\n\n            return buffer.GetData<byte>(commandList);\n        }\n\n        /// <summary>\n        /// Expand vertices using index buffer (if existing), and remove it.\n        /// </summary>\n        /// <param name=\"meshData\">The mesh data.</param>\n        public static unsafe void RemoveIndexBuffer(this MeshDraw meshData)\n        {\n            if (meshData.IndexBuffer == null)\n                return;\n\n            // For now, require a MeshData with only one vertex buffer and a 32 bit full index buffer\n            if (meshData.VertexBuffers.Length != 1 || !meshData.IndexBuffer.Is32Bit\n                || meshData.StartLocation != 0 || meshData.DrawCount != meshData.IndexBuffer.Count)\n                throw new NotImplementedException();\n","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Extensions/IndexExtensions.cs#L5-L41","documentation":"GetDataSafe retrieves index buffer bytes, first from the CPU-side serialization data; if absent it needs a commandList to copy the data back from the GPU. When neither is available (no serialized CPU content and commandList is null) an InvalidOperationException is thrown because GPU readback is impossible without a command list.","triggerScenarios":"Calling IndexExtensions.GetDataSafe on a GraphicsResource buffer whose GetSerializationData() returns null (never uploaded with CPU content retained) and passing null for commandList, e.g. on the game thread instead of a render context.","commonSituations":"Asset processing at runtime after CPU content was released, or calling from non-render code without acquiring CommandList from a graphics context.","solutions":["Pass a valid CommandList (e.g. from the render context) so the GPU buffer can be read back","Keep the buffer's serialization data (CPU content) available when the asset is loaded","Re-load the asset with CPU-side data retained if the buffer was created GPU-only"],"exampleFix":"// before\nvar data = indexBuffer.GetDataSafe(null);\n// after\nvar data = indexBuffer.GetDataSafe(renderContext.CommandList);","handlingStrategy":"validation","validationCode":"if (buffer.GetSerializationData() == null && commandList == null)\n    throw new InvalidOperationException(\"GetDataSafe needs a CommandList for GPU-only buffers\");\nvar data = buffer.GetDataSafe(commandList);","typeGuard":"bool canRead = buffer.GetSerializationData() != null || commandList != null;","tryCatchPattern":"try { var data = buffer.GetDataSafe(commandList); } catch (InvalidOperationException) { /* no CPU data and no command list */ }","preventionTips":["Always pass the current render context's CommandList when reading GPU buffers","Keep serialization (CPU) data on assets that need runtime readback","Perform buffer readbacks during rendering, not arbitrary game-thread code"],"tags":["rendering","gpu-readback","invalid-operation"],"backgroundTag":"missing-required-argument","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"}