{"record":{"id":"a0bc5d9e341c7ea8","repo":"stride3d/stride","slug":"only-buffers-and-textures-can-be-mapped","errorCode":null,"errorMessage":"Only Buffers and Textures can be mapped","messagePattern":"Only Buffers and Textures can be mapped","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs","lineNumber":2247,"sourceCode":"\n                rowPitch = texture.ComputeRowPitch(subResourceIndex % texture.MipLevelCount);\n                depthStride = texture.ComputeSlicePitch(subResourceIndex % texture.MipLevelCount);\n\n                if (usage == GraphicsResourceUsage.Staging)\n                {\n                    // Internally it's a Buffer, so adapt resource index and offset\n                    offsetInBytes = texture.ComputeBufferOffset(subResourceIndex, depthSlice: 0);\n                    subResourceIndex = 0;\n                }\n            }\n            else if (resource is Buffer buffer)\n            {\n                usage = buffer.Usage;\n\n                if (lengthInBytes == 0)\n                    lengthInBytes = buffer.SizeInBytes;\n            }\n            else throw new ArgumentException(\"Only Buffers and Textures can be mapped\", nameof(resource));\n\n            if (mapMode is MapMode.Read or MapMode.ReadWrite or MapMode.Write)\n            {\n                // Is non-staging even possible for Read/Write?\n                if (usage != GraphicsResourceUsage.Staging)\n                    throw new ArgumentException(\"Read / Write / ReadWrite is only supported for staging resources\", nameof(mapMode));\n            }\n\n            // NOTE: This path is quite slow (it creates a new resource).\n            //       Once we switch to D3D12 / Vulkan only, we should probably get rid of this use case\n            //       by pooling and reusing buffers internally, or explicitly managed at the caller side\n            if (mapMode == MapMode.WriteDiscard)\n            {\n                // Mark old resource for deletion once Command List are executed\n                resource.OnDestroyed();\n\n                // Create new resource\n                resource.OnRecreate();","sourceCodeStart":2229,"sourceCodeEnd":2265,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs#L2229-L2265","documentation":"CommandList.Map on Direct3D12 only accepts GraphicsMapMap resource types of Buffer or Texture; anything else throws ArgumentException naming the resource parameter. Mapping is defined solely for these two resource kinds.","triggerScenarios":"Calling CommandList.Map(resource, mapMode, subIndex, offset, length) with a resource that is neither Buffer nor Texture (e.g. wrong variable, custom resource, null).","commonSituations":"Passing a RenderTarget/other wrapper where the underlying texture was intended; generic helper code that forwards any GraphicsResource to Map; refactors changing resource types.","solutions":["Pass the Buffer or Texture you intend to map, not a wrapper or other GraphicsResource.","If you hold a more general type, pattern-match to Texture/Buffer before mapping.","Null-check the resource before calling Map.","For other resource kinds, use their dedicated CPU access APIs instead of Map."],"exampleFix":"// before\ncommandList.Map(renderTargetWrapper, MapMode.Read, 0);\n// after\nif (wrapper.Texture is Texture tex)\n    MappedResource m = commandList.Map(tex, MapMode.Read, 0);","handlingStrategy":"type-guard","validationCode":"if (resource is not Buffer && resource is not Texture)\n    throw new ArgumentException(\"Map requires a Buffer or Texture\", nameof(resource));","typeGuard":"static bool IsMappable(GraphicsResource r) => r is Buffer or Texture;","tryCatchPattern":"try { var mapped = commandList.Map(resource, MapMode.Read, 0); }\ncatch (ArgumentException ex) { log.Error(\"Map: only Buffer/Texture supported\", ex); }","preventionTips":["Pass the underlying texture/buffer, not wrappers like RenderTarget.","Type-check in generic resource helpers before mapping.","Null-check resources before Map."],"tags":["direct3d12","graphics","map","invalid-argument"],"backgroundTag":"invalid-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"}