{"record":{"id":"a362a5977061bfe2","repo":"stride3d/stride","slug":"argumentnullexception-data","errorCode":null,"errorMessage":"ArgumentNullException: data","messagePattern":"ArgumentNullException: data","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/Heightmap.cs","lineNumber":76,"sourceCode":"        /// The range of the height.\n        /// </summary>\n        /// <remarks>\n        /// X is min height and Y is max height.\n        /// (height * HeightScale) should be in this range.\n        /// Positive and negative heights can not be handle at the same time when the height type is Byte.\n        /// </remarks>\n        [DataMember(60)]\n        public Vector2 HeightRange;\n\n        /// <summary>\n        /// Used to calculate the height when the height type is Short or Byte. HeightScale should be 1 when the height type is Float.\n        /// </summary>\n        [DataMember(70)]\n        public float HeightScale;\n\n        public static Heightmap Create<T>(Int2 size, HeightfieldTypes heightType, Vector2 heightRange, float heightScale, T[] data)\n        {\n            if (data == null) throw new ArgumentNullException(nameof(data));\n\n            HeightmapUtils.CheckHeightParameters(size, heightType, heightRange, heightScale, true);\n\n            var length = size.X * size.Y;\n\n            switch (data)\n            {\n                case float[] floats when floats.Length == length: break;\n                case short[] shorts when shorts.Length == length: break;\n                case byte[] bytes when bytes.Length == length: break;\n                default: throw new ArgumentException($\"{ typeof(T[]) } is not supported in { heightType } height type. Or { nameof(data) }.{ nameof(data).Length } doesn't match { nameof(size) }.\");\n            }\n\n            var heightmap = new Heightmap\n            {\n                HeightType = heightType,\n                Size = size,\n                HeightRange = heightRange,","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/Heightmap.cs#L58-L94","documentation":"Heightmap.Create validates that the data array parameter is non-null before building the heightmap. Passing a null data array throws ArgumentNullException with the parameter name 'data'. This is a fail-fast guard against constructing a heightmap with no height data.","triggerScenarios":"Calling Heightmap.Create<T>(size, heightType, heightRange, heightScale, data) with data == null, e.g. from HeightmapDeserialization failing, a data member not yet populated, or code that computes the array conditionally and skips initialization.","commonSituations":"Loading terrain assets where the raw height array failed to deserialize; procedurally generating heightmaps and forgetting to fill the array; passing a field that defaults to null before asset load completes.","solutions":["Ensure the data array is allocated and populated before calling Heightmap.Create.","Check for null at the call site: if (data == null) { /* load or generate */ }","If data comes from asset deserialization, verify the asset loaded successfully before creating the heightmap.","For procedural terrain, initialize the array to the correct size (size.X * size.Y) before calling Create."],"exampleFix":"// before\nvar heightmap = Heightmap.Create(size, HeightfieldTypes.Float, range, 1f, data); // data may be null\n\n// after\nif (data == null)\n    data = new float[size.X * size.Y];\nvar heightmap = Heightmap.Create(size, HeightfieldTypes.Float, range, 1f, data);","handlingStrategy":"validation","validationCode":"if (data == null) throw new InvalidOperationException(\"Heightmap data must be loaded before Heightmap.Create.\");","typeGuard":"bool HasHeightData<T>(T[] data) => data is { Length: > 0 };","tryCatchPattern":"try { var hm = Heightmap.Create(size, type, range, scale, data); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"data\") { Logger.Error(\"Heightmap data array was null\"); }","preventionTips":["Always allocate and populate the data array before calling Create.","Validate deserialized assets for null data before use.","Initialize procedural heightmaps to size.X * size.Y elements."],"tags":["physics","heightmap","argument-null","terrain"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}