stride3d/stride · error · ArgumentNullException
ArgumentNullException: heightmap
Error message
ArgumentNullException: heightmap
What it means
The HeightmapExtensions.IsValid extension method validates the heightmap's height data integrity, but first asserts the heightmap instance itself is non-null, throwing ArgumentNullException('heightmap'). Stride uses this fail-fast guard so callers do not silently treat a missing heightmap as 'valid' or 'invalid'.
Solutions
- Null-check the Heightmap before calling IsValid: if (heightmap != null && heightmap.IsValid()).
- Ensure terrain/asset loading succeeded and the HeightmapData field was populated before validation.
- Treat a null heightmap explicitly in game logic (e.g. generate a default flat heightmap) instead of passing null into extension checks.
- Wrap the validation call in try-catch for ArgumentNullException when the heightmap source is untrusted.
Example fix
// before
if (heightmap.IsValid()) { ... } // throws if heightmap is null
// after
if (heightmap != null && heightmap.IsValid()) { ... } Defensive patterns
Strategy: type-guard
Validate before calling
if (heightmap is null) return false; // or handle explicitly before calling IsValid return heightmap.IsValid();
Type guard
bool TryValidate(Heightmap heightmap, out bool isValid)
{
if (heightmap is null) { isValid = false; return false; }
isValid = heightmap.IsValid();
return true;
} Try / catch
try { valid = heightmap.IsValid(); }
catch (ArgumentNullException ex) when (ex.ParamName == "heightmap") { valid = false; } Prevention
- Null-check the Heightmap receiver before calling extension methods on it.
- Ensure terrain assets loaded successfully before validating their heightmaps.
- Treat null heightmaps as an explicit 'missing data' case in game logic rather than passing them to validators.
When it happens
Trigger: Calling heightmap.IsValid() where the receiver is null — e.g. the heightmap was never assigned, a terrain component's HeightmapData is null, or an asset failed to load and produced a null reference that was then checked for validity.
Common situations: Checking validity of a heightmap loaded from an asset that failed to deserialize; validating optional heightmap data before simulation setup; pipeline code that passes a null heightmap from a failed import.
Related errors
- ArgumentNullException: data
- is not supported in height type. Or . doesn't match .
- format is not supported.
- . should be greater than .
- height type is not supported.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/280c5e689cea710c.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Physics/Engine/HeightmapExtensions.cs:15
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Linq;
using Stride.Core.Annotations;
using Stride.Core.Mathematics;
using Stride.Graphics;
namespace Stride.Physics
{
public static class HeightmapExtensions
{
public static bool IsValid([NotNull] this Heightmap heightmap)
{
if (heightmap == null) throw new ArgumentNullException(nameof(heightmap));
bool IsValidHeights()
{
var length = heightmap.Size.X * heightmap.Size.Y;
switch (heightmap.HeightType)
{
case HeightfieldTypes.Float when heightmap.Floats != null && heightmap.Floats.Length == length:
return true;
case HeightfieldTypes.Short when heightmap.Shorts != null && heightmap.Shorts.Length == length:
return true;
case HeightfieldTypes.Byte when heightmap.Bytes != null && heightmap.Bytes.Length == length:
return true;
}
return false;View on GitHub (pinned to 96fad776d2)