{"record":{"id":"b83669314eca2ea8","repo":"stride3d/stride","slug":"unmanagedarray","errorCode":null,"errorMessage":"unmanagedArray","messagePattern":"unmanagedArray","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/UnmanagedArrayExtensions.cs","lineNumber":20,"sourceCode":"// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.\nusing System;\nusing Stride.Core;\n\nnamespace Stride.Physics\n{\n    public static class UnmanagedArrayExtensions\n    {\n        /// <summary>\n        /// Fill the array with specific value.\n        /// </summary>\n        /// <typeparam name=\"T\">The type param of UnmanagedArray</typeparam>\n        /// <param name=\"unmanagedArray\">The destination to fill.</param>\n        /// <param name=\"value\">The value used to fill.</param>\n        /// <param name=\"index\">The start index of the destination to fill.</param>\n        /// <param name=\"fillLength\">The filling length.</param>\n        public static void Fill<T>(this UnmanagedArray<T> unmanagedArray, T value, int index, int fillLength) where T : struct\n        {\n            if (unmanagedArray == null) throw new ArgumentNullException(nameof(unmanagedArray));\n\n            var length = unmanagedArray.Length;\n            var endIndex = index + fillLength;\n\n            if (length <= index) throw new IndexOutOfRangeException(nameof(index));\n            if (length < endIndex) throw new ArgumentException($\"{ nameof(unmanagedArray) }.{ nameof(unmanagedArray.Length) } is not enough to fill.\");\n\n            for (int i = index; i < endIndex; ++i)\n            {\n                unmanagedArray[i] = value;\n            }\n        }\n    }\n}\n","sourceCodeStart":2,"sourceCodeEnd":35,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/UnmanagedArrayExtensions.cs#L2-L35","documentation":"UnmanagedArrayExtensions.Fill validates its destination before filling. A null unmanagedArray cannot be written to, so an ArgumentNullException naming the 'unmanagedArray' parameter is thrown. This is a guard against passing an uninitialized native memory buffer.","triggerScenarios":"Calling unmanagedArray.Fill(value, index, fillLength) as an extension method on a null UnmanagedArray<T> reference, e.g. an array that failed allocation or was never assigned.","commonSituations":"Native buffer creation failed silently earlier, or a struct field holding the unmanaged array was default-initialized and used before allocation.","solutions":["Ensure the UnmanagedArray<T> is allocated before calling Fill","Null-check the array at the call site before filling","Fix the earlier allocation/initialization path that left the array null"],"exampleFix":"// before\nbuffer.Fill(0f, 0, count);\n// after\nif (buffer != null) buffer.Fill(0f, 0, count);","handlingStrategy":"type-guard","validationCode":"if (array == null) throw new InvalidOperationException(\"UnmanagedArray not allocated\");\narray.Fill(value, index, fillLength);","typeGuard":"static bool IsAllocated<T>(UnmanagedArray<T> a) where T : struct => a != null && a.Length > 0;","tryCatchPattern":"try { array.Fill(value, index, fillLength); } catch (ArgumentNullException) { /* array was never allocated */ }","preventionTips":["Allocate UnmanagedArray in constructors/factory methods so it is never default(null)","Use nullable-aware annotations and treat uninitialized arrays as errors early"],"tags":["null-argument","physics","unmanaged-memory"],"backgroundTag":"null-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"}