{"record":{"id":"fdd9c07abb7e4f2b","repo":"stride3d/stride","slug":"unsupported-graphics-resource-only-textures-buffers-and","errorCode":null,"errorMessage":"Unsupported Graphics Resource. Only Textures, Buffers and QueryPools are supported","messagePattern":"Unsupported Graphics Resource\\. Only Textures, Buffers and QueryPools are supported","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/GraphicsResourceAllocator.cs","lineNumber":473,"sourceCode":"        ///   or if the Graphics Resource was not allocated by this allocator.\n        /// </exception>\n        /// <exception cref=\"ArgumentException\">\n        ///   The <paramref name=\"referenceDelta\"/> is invalid. It cannot make the reference count of the <paramref name=\"resource\"/> negative.\n        /// </exception>\n        private void UpdateReference(GraphicsResourceBase resource, int referenceDelta)\n        {\n            if (resource is null)\n                return;\n\n            bool resourceFound = false;\n\n            resourceFound = resource switch\n            {\n                Texture texture => UpdateReferenceCount(textureCache, texture, GetTextureDescription, referenceDelta),\n                Buffer buffer => UpdateReferenceCount(bufferCache, buffer, GetBufferDescription, referenceDelta),\n                QueryPool queryPool => UpdateReferenceCount(queryPoolCache, queryPool, GetQueryPoolDescription, referenceDelta),\n\n                _ => throw new ArgumentException(\"Unsupported Graphics Resource. Only Textures, Buffers and QueryPools are supported\", nameof(resource))\n            };\n\n            if (!resourceFound)\n                throw new ArgumentException(\"The Graphics Resource was not allocated by this allocator\", nameof(resource));\n        }\n\n        /// <summary>\n        ///   Updates the reference count for a specified Graphics Resource.\n        /// </summary>\n        /// <typeparam name=\"TResource\">The type of the Graphics Resource.</typeparam>\n        /// <typeparam name=\"TDescription\">The type of an object that describes the characteristics of the Graphics Resource.</typeparam>\n        /// <param name=\"cache\">The cache of allocated Graphics Resources of the intended type.</param>\n        /// <param name=\"resource\">The Graphics Resource whose reference count is to be updated.</param>\n        /// <param name=\"getDescription\">\n        ///   A delegate that retrieves the actual description of a Graphics Resource.\n        ///   See <see cref=\"GetTextureDescription\"/>, <see cref=\"GetBufferDescription\"/>, or <see cref=\"GetQueryPoolDescription\"/> for examples.\n        /// </param>\n        /// <param name=\"referenceDelta\">","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/GraphicsResourceAllocator.cs#L455-L491","documentation":"GraphicsResourceAllocator.UpdateReference only knows how to track Texture, Buffer, and QueryPool resources; any other GraphicsResourceBase-derived type hits the switch's default arm and throws ArgumentException naming the 'resource' parameter. The allocator maintains per-type caches for exactly these three kinds.","triggerScenarios":"Calling AddReference or ReleaseReference with a graphics resource that is not a Texture, Buffer, or QueryPool (e.g. some custom GraphicsResourceBase subclass or another resource type).","commonSituations":"Custom engine extensions introducing new resource kinds and passing them to the allocator; misuse of the allocator API assuming it tracks all GraphicsResourceBase types; type confusion where a wrapper object is passed instead of the underlying resource.","solutions":["Only pass Texture, Buffer, or QueryPool instances to AddReference/ReleaseReference.","If a new resource kind must be tracked, extend the allocator with an additional cache and switch arm.","Unwrap or convert wrapper objects to the underlying supported resource before calling."],"exampleFix":"// before\nallocator.AddReference(myCustomResource); // not supported\n// after\nif (myCustomResource is Texture t) allocator.AddReference(t);\nelse throw new NotSupportedException(\"Only Texture/Buffer/QueryPool are tracked\");","handlingStrategy":"type-guard","validationCode":"if (resource is not (Texture or Buffer or QueryPool))\n    throw new NotSupportedException(\"Allocator tracks only Texture/Buffer/QueryPool\");","typeGuard":"bool Trackable(GraphicsResourceBase r) => r is Texture or Buffer or QueryPool;","tryCatchPattern":"try { allocator.AddReference(resource); }\ncatch (ArgumentException ex) { log.Error($\"Unsupported resource {resource.GetType().Name}\", ex); }","preventionTips":["Only pass Texture/Buffer/QueryPool to allocator reference APIs","Extend the allocator explicitly for new resource kinds","Avoid wrapping resources before ref-counting"],"tags":["csharp","graphics","unsupported-type"],"backgroundTag":"invalid-argument-value","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"}