{"record":{"id":"29c32f54996e8edc","repo":"stride3d/stride","slug":"lockslim","errorCode":null,"errorMessage":"lockSlim","messagePattern":"lockSlim","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Shapes/HeightfieldColliderShape.cs","lineNumber":180,"sourceCode":"    {\n        return new HeightArrayLock(HeightArrayLock.LockTypes.ReadWrite, lockSlim);\n    }\n\n    public class HeightArrayLock : IDisposable\n    {\n        public enum LockTypes\n        {\n            Read = 0,\n            ReadWrite = 1,\n        }\n\n        private readonly ReaderWriterLockSlim readerWriterLockSlim;\n\n        internal HeightArrayLock(LockTypes lockType, ReaderWriterLockSlim lockSlim)\n        {\n            if (lockSlim == null)\n            {\n                throw new ArgumentNullException(nameof(lockSlim));\n            }\n\n            readerWriterLockSlim = lockSlim;\n\n            switch (lockType)\n            {\n                case LockTypes.Read:\n                    readerWriterLockSlim.EnterReadLock();\n                    break;\n                case LockTypes.ReadWrite:\n                    readerWriterLockSlim.EnterWriteLock();\n                    break;\n                default:\n                    throw new ArgumentException($\"{ nameof(lockType) } is invalid type\");\n            }\n        }\n\n        public void Unlock()","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Shapes/HeightfieldColliderShape.cs#L162-L198","documentation":"HeightfieldColliderShape.HeightArrayLock is a scoped lock helper wrapping a ReaderWriterLockSlim. It throws ArgumentNullException when the passed lockSlim is null, since unlocking later would be impossible and the lock object is mandatory.","triggerScenarios":"Constructing HeightArrayLock(lockType, null) — typically only reachable via internal misuse, since the ReaderWriterLockSlim is a private field of HeightfieldColliderShape initialized with the shape.","commonSituations":"Custom subclasses or refactored code that constructs the lock handle before the heightfield's lock is initialized (e.g. in a partially constructed object).","solutions":["Ensure the HeightfieldColliderShape is fully constructed (its readerWriterLockSlim field initialized) before acquiring a HeightArrayLock.","Pass a non-null ReaderWriterLockSlim instance when constructing HeightArrayLock directly.","If using the public Lock* APIs on the shape, don't construct the lock handle manually."],"exampleFix":"// before\nvar l = new HeightfieldColliderShape.HeightArrayLock(LockTypes.Read, null);\n// after\nvar l = new HeightfieldColliderShape.HeightArrayLock(LockTypes.Read, shape.LockSlim);","handlingStrategy":"type-guard","validationCode":"if (lockSlim == null) throw new InvalidOperationException(\"ReaderWriterLockSlim must be initialized before locking.\");","typeGuard":"bool CanLock(ReaderWriterLockSlim l) => l != null;","tryCatchPattern":"try { var l = new HeightArrayLock(LockTypes.Read, lockSlim); }\ncatch (ArgumentNullException) { /* lazily initialize the lock */ }","preventionTips":["Initialize ReaderWriterLockSlim in field initializers, not late in the lifecycle.","Use the shape's public Lock APIs instead of constructing HeightArrayLock manually.","Guard against using partially constructed shapes."],"tags":["physics","null-argument","locking"],"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"}