{"record":{"id":"11e8f49be29fc711","repo":"stride3d/stride","slug":"the-graphics-resource-was-not-allocated-by-this-allocator","errorCode":null,"errorMessage":"The Graphics Resource was not allocated by this allocator","messagePattern":"The Graphics Resource was not allocated by this allocator","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/GraphicsResourceAllocator.cs","lineNumber":477,"sourceCode":"        /// </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\">\n        ///   The change in the reference count. Positive values increase the count, while negative values decrease it.\n        /// </param>\n        /// <returns>\n        ///   <see langword=\"true\"/> if the reference count for <paramref name=\"resource\"/> was updated; <see langword=\"false\"/> otherwise.","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/GraphicsResourceAllocator.cs#L459-L495","documentation":"UpdateReference looks up the resource in the allocator's per-type caches (textureCache, bufferCache, queryPoolCache). If the resource is a supported type but was never allocated by (or registered with) this allocator instance, resourceFound is false and an ArgumentException naming 'resource' is thrown. Each allocator only manages resources it created itself.","triggerScenarios":"Calling AddReference/ReleaseReference with a Texture/Buffer/QueryPool that was created by another allocator, created manually (e.g. Buffer.New directly), or already fully released and evicted from the cache.","commonSituations":"Mixing resources between two allocator instances (e.g. one per GraphicsDevice or scene); creating buffers/textures outside the allocator then trying to reference-count them; double-releasing a temporary resource that has since been recycled.","solutions":["Allocate the resource through this same GraphicsResourceAllocator instance (AllocateTexture/AllocateBuffer/etc.) before adding references.","Verify you are passing the allocator instance that originally created the resource.","Check the resource has not already been released and removed from the allocator's cache.","Track a 'recycled' resource by its new incarnation from the allocator rather than a stale reference."],"exampleFix":"// before\nvar buffer = Buffer.New(graphicsDevice, size);\nallocator.AddReference(buffer); // throws: not allocated by allocator\n// after\nvar buffer = allocator.AllocateBuffer(new BufferDescription(size), bufferPool);","handlingStrategy":"validation","validationCode":"if (!allocator.OwnsResource(texture)) // or track allocations yourself\n    throw new InvalidOperationException(\"Resource must be allocated by this allocator\");\nallocator.AddReference(texture);","typeGuard":"bool AllocatedByThis(Allocator a, GraphicsResourceBase r) => r.Allocator == a;","tryCatchPattern":"try { allocator.ReleaseReference(resource); }\ncatch (ArgumentException ex) { log.Warn(\"resource not owned by allocator\", ex); }","preventionTips":["Allocate resources through the same allocator that releases them","Keep one allocator per device/pipeline scope","Never manually release already-recycled temporaries"],"tags":["csharp","graphics","resource-lifetime"],"backgroundTag":"resource-not-found","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}