stride3d/stride · error · ArgumentNullException
resource
Error message
resource
What it means
Argument-null validation on the resource parameter of CommandList's subresource Map method (Vulkan backend). Mapping a subresource requires a valid GPU resource; a null resource has no Vulkan memory to map, so the method throws ArgumentNullException named 'resource', as declared in its documentation.
Solutions
- Ensure the Texture/Buffer was successfully created before mapping
- Check resource creation return values and dispose logic that may null the field
- Guard the call with a null check and log/early-return instead of reaching the API
Example fix
// before
cmdList.MapSubResource(texture, 0, MapMode.Write);
// after
if (texture == null) throw new InvalidOperationException("texture not initialized");
cmdList.MapSubResource(texture, 0, MapMode.Write); Defensive patterns
Strategy: validation
Validate before calling
if (resource == null) return; // or log and bail before calling MapSubResource
Type guard
if (resource is Texture t) { /* safe to map */ } else if (resource is Buffer b) { /* safe to map */ } Try / catch
try { var mapped = cmdList.MapSubResource(res, 0, MapMode.Write); } catch (ArgumentNullException) { /* resource was null; initialize it */ } Prevention
- Validate resource fields right after creation
- Avoid nulling disposed resources if they may still be mapped later
- Wrap resource creation and mapping in the same initialization scope
When it happens
Trigger: Calling CommandList.MapSubResource(null, ...) with a texture/buffer variable that was never assigned or was disposed and cleared to null.
Common situations: Deferred initialization where the resource creation call failed silently; disposed resource set to null; typo assigning to a local instead of the field.
Related errors
- commandLists
- DeviceWindowHandle cannot be null
- Value cannot be null. (Parameter 'location')
- Value cannot be null. (Parameter 'asset')
- Value cannot be null. (Parameter 'value')
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/57b7a076539172bb.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs:1547
}
}
}
// TODO GRAPHICS REFACTOR what should we do with this?
/// <summary>
/// Maps a subresource.
/// </summary>
/// <param name="resource">The resource.</param>
/// <param name="subResourceIndex">Index of the sub resource.</param>
/// <param name="mapMode">The map mode.</param>
/// <param name="doNotWait">if set to <c>true</c> this method will return immediately if the resource is still being used by the GPU for writing. Default is false</param>
/// <param name="offsetInBytes">The offset information in bytes.</param>
/// <param name="lengthInBytes">The length information in bytes.</param>
/// <returns>Pointer to the sub resource to map.</returns>
public unsafe partial MappedResource MapSubResource(GraphicsResource resource, int subResourceIndex, MapMode mapMode, bool doNotWait = false, int offsetInBytes = 0, int lengthInBytes = 0)
{
if (resource == null) throw new ArgumentNullException("resource");
var rowPitch = 0;
var usage = GraphicsResourceUsage.Default;
if (resource is Texture texture)
{
usage = texture.Usage;
if (lengthInBytes == 0)
lengthInBytes = texture.ComputeSubResourceSize(subResourceIndex);
rowPitch = texture.ComputeRowPitch(subResourceIndex % texture.MipLevelCount);
offsetInBytes += texture.ComputeBufferOffset(subResourceIndex, depthSlice: 0);
}
else
{
if (resource is Buffer buffer)
{
usage = buffer.Usage;View on GitHub (pinned to 96fad776d2)