{"record":{"id":"5f99174942428d1d","repo":"stride3d/stride","slug":"graphicsdevice-graphicsresourceallocator","errorCode":null,"errorMessage":"graphicsDevice","messagePattern":"graphicsDevice","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/GraphicsResourceAllocator.cs","lineNumber":94,"sourceCode":"        private readonly object thisLock = new();\n\n        private readonly TextureCache textureCache = [];      // Cache for Textures by their TextureDescription\n        private readonly BufferCache bufferCache = [];        // Cache for Buffers by their BufferDescription\n        private readonly QueryPoolCache queryPoolCache = [];  // Cache for QueryPools by their QueryPoolDescription\n\n        private readonly CreateTextureDelegate createTextureDelegate;\n        private readonly CreateBufferDelegate createBufferDelegate;\n        private readonly CreateQueryPoolDelegate createQueryPoolDelegate;\n\n\n        /// <summary>\n        ///   Initializes a new instance of the <see cref=\"GraphicsResourceAllocator\"/> class.\n        /// </summary>\n        /// <param name=\"graphicsDevice\">The Graphics Device.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"graphicsDevice\"/> is <see langword=\"null\"/>.</exception>\n        public GraphicsResourceAllocator(GraphicsDevice graphicsDevice)\n        {\n            GraphicsDevice = graphicsDevice ?? throw new ArgumentNullException(nameof(graphicsDevice));\n\n            // We cache the delegates to avoid allocations on each call. They can't be static because they\n            // can be overridden in derived classes\n            createTextureDelegate = CreateTexture;\n            createBufferDelegate = CreateBuffer;\n            createQueryPoolDelegate = CreateQueryPool;\n        }\n\n\n        /// <summary>\n        ///   Gets or sets the Graphics Device.\n        /// </summary>\n        private GraphicsDevice GraphicsDevice { get; }\n\n        /// <summary>\n        ///   Gets the services registry.\n        /// </summary>\n        public IServiceRegistry Services { get; private set; } // TODO: Never set, never read, remove this property?","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/GraphicsResourceAllocator.cs#L76-L112","documentation":"The GraphicsResourceAllocator constructor requires a non-null GraphicsDevice instance; passing null throws ArgumentNullException with parameter name 'graphicsDevice'. The allocator stores the device and delegates to it for creating textures, buffers and query pools, so it cannot function without one.","triggerScenarios":"Calling new GraphicsResourceAllocator(null) directly, or passing a GraphicsDevice field/property that is still null because the device was not yet created or initialization failed silently.","commonSituations":"Constructing the allocator before GraphicsDevice initialization in a game or render pipeline; a DI container injecting an unregistered (null) device; refactoring that reordered device creation after allocator creation.","solutions":["Create the GraphicsDevice before constructing GraphicsResourceAllocator and pass the initialized instance.","Assert the device is non-null at the call site to catch ordering issues early.","Fix DI registration so a GraphicsDevice is actually provided."],"exampleFix":"// before\nvar allocator = new GraphicsResourceAllocator(null);\n// after\nvar allocator = new GraphicsResourceAllocator(graphicsDevice); // ensure graphicsDevice is initialized first","handlingStrategy":"validation","validationCode":"if (graphicsDevice is null)\n    throw new InvalidOperationException(\"GraphicsDevice must be created before the allocator\");\nvar allocator = new GraphicsResourceAllocator(graphicsDevice);","typeGuard":"bool HasDevice(GraphicsDevice d) => d is not null;","tryCatchPattern":"try { allocator = new GraphicsResourceAllocator(device); }\ncatch (ArgumentNullException ex) { log.Error(\"null graphicsDevice\", ex); throw; }","preventionTips":["Create GraphicsDevice before dependents","Use constructor ordering/DI that guarantees device availability","Assert non-null early in pipeline setup"],"tags":["csharp","null-argument","graphics"],"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"}