{"record":{"id":"f5148ed2c024f461","repo":"stride3d/stride","slug":"capacity-must-be-greater-than-0","errorCode":null,"errorMessage":"Capacity must be greater than 0.","messagePattern":"Capacity must be greater than 0\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Collections/Dequeue.cs","lineNumber":74,"sourceCode":"\n    /// <summary>\n    /// The offset into <see cref=\"buffer\"/> where the view begins.\n    /// </summary>\n    private int offset;\n\n    /// <summary>\n    /// Used to wrap around indices when incrementing outside buffer range\n    /// </summary>\n    private int mask;\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Deque&lt;T&gt;\"/> class with the specified capacity.\n    /// </summary>\n    /// <param name=\"capacity\">The initial capacity. Must be a power of two greater than <c>0</c>.</param>\n    public Deque(int capacity)\n    {\n        if (capacity < 1)\n            throw new ArgumentOutOfRangeException(nameof(capacity), \"Capacity must be greater than 0.\");\n\n        if (int.IsPow2(capacity) == false)\n            throw new InvalidOperationException(\"Capacity must be a power of two\");\n\n        buffer = new T[capacity];\n        mask = buffer.Length - 1;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Deque&lt;T&gt;\"/> class.\n    /// </summary>\n    public Deque()\n        : this(DefaultCapacity)\n    {\n    }\n\n    #region GenericListImplementations\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Collections/Dequeue.cs#L56-L92","documentation":"Stride's Deque<T> is a ring-buffer deque; its internal indexing requires a buffer of at least one element. The capacity constructor validates this and throws ArgumentOutOfRangeException when capacity < 1, because a zero or negative capacity cannot back the ring buffer.","triggerScenarios":"new Deque<T>(0) — e.g. default(int) or an uninitialized config value used as capacity; a computed capacity such as items.Count - 1 that evaluates to 0 on empty input.","commonSituations":"Pooling code sizing the deque from an empty source collection; configuration-driven initial capacities defaulting to 0; refactors that changed a 'size' parameter into a 'capacity' parameter.","solutions":["Pass a capacity of at least 1 when constructing the deque.","Clamp: Math.Max(1, requestedCapacity).","Use the parameterless Deque<T>() constructor when no specific capacity is needed."],"exampleFix":"// before\nvar deque = new Deque<Entity>(items.Count - 1); // 0 when items is empty\n\n// after\nvar deque = new Deque<Entity>(Math.Max(1, items.Count));","handlingStrategy":"validation","validationCode":"int capacity = ComputeCapacity();\nif (capacity < 1)\n    capacity = 1;\nvar deque = new Deque<Entity>(capacity);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp computed capacities with Math.Max(1, value).","Use the parameterless Deque<T>() constructor when capacity is unknown.","Beware of expressions like items.Count - 1 that hit 0 on empty input."],"tags":["csharp","stride-core","collections","argument-validation"],"backgroundTag":"argument-out-of-range","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"}