{"record":{"id":"740b431547965c7e","repo":"stride3d/stride","slug":"the-method-execution-path-is-not-within-a-drawcore-operation","errorCode":null,"errorMessage":"The method execution path is not within a DrawCore operation","messagePattern":"The method execution path is not within a DrawCore operation","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Rendering/RendererCoreBase.cs","lineNumber":192,"sourceCode":"        /// <summary>\n        /// Pushes a new scoped resource to the current Draw.\n        /// </summary>\n        /// <param name=\"resource\">The scoped resource</param>\n        /// <returns></returns>\n        protected T PushScopedResource<T>(T resource) where T : GraphicsResource\n        {\n            scopedResources.Add(resource);\n            return resource;\n        }\n\n        /// <summary>\n        /// Checks that the current execution path is between a PreDraw/PostDraw sequence and throws and exception if not.\n        /// </summary>\n        protected void CheckIsInDrawCore()\n        {\n            if (!isInDrawCore)\n            {\n                throw new InvalidOperationException(\"The method execution path is not within a DrawCore operation\");\n            }\n        }\n\n        protected override void Destroy()\n        {\n            // If this instance is destroyed and not unload, force an unload before destryoing it completely\n            if (Context != null)\n            {\n                Unload();\n            }\n            base.Destroy();\n        }\n\n        protected T ToLoadAndUnload<T>(T effect) where T : class, IGraphicsRendererCore\n        {\n            if (effect == null) throw new ArgumentNullException(\"effect\");\n            effect.Initialize(Context);\n            subRenderersToUnload.Add(effect);","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Rendering/RendererCoreBase.cs#L174-L210","documentation":"RendererCoreBase restricts allocation of transient ('scoped') GPU resources to the Draw phase. CheckIsInDrawCore asserts the internal isInDrawCore flag set between PreDrawCoreInternal and PostDrawCoreInternal; NewScopedBuffer (and similar New* calls) call it, and if you call them outside DrawCore the lifetime of the scoped resource cannot be managed correctly, so an InvalidOperationException is thrown.","triggerScenarios":"Calling NewScopedBuffer / NewScopedTexture (via this.Allocation or CommandList-related helpers) from Initialize, LoadContent, a custom render stage callback outside DrawCore, a background thread, or any code not invoked between PreDraw and PostDraw of the renderer.","commonSituations":"Creating buffers in a RenderFeature's InitializeCore instead of DrawCore; allocating resources in event handlers or game-update code while touching a renderer; calling render-feature methods manually rather than through the render pipeline.","solutions":["Move the NewScopedBuffer call into your RenderFeature's DrawCore (or Unload via PersistentResources for reusable buffers)","For long-lived resources, use persistent allocations (e.g. PushPersistentResource / CreatePersistentResource) instead of scoped ones","If you need data prepared outside draw, stage it in CPU-side buffers and create the scoped buffer inside DrawCore"],"exampleFix":"// before\npublic override void InitializeCore()\n{\n    var buf = NewScopedBuffer(data, 0, size); // throws: not in DrawCore\n}\n// after\nprotected override void DrawCore(RenderDrawContext context)\n{\n    var buf = NewScopedBuffer(data, 0, size);\n}","handlingStrategy":"validation","validationCode":"if (!isInDrawCore)\n    throw new InvalidOperationException(\"Allocate scoped resources only inside DrawCore.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var buf = NewScopedBuffer(data, 0, size);\n}\ncatch (InvalidOperationException)\n{\n    Logger.Warning(\"Scoped allocation outside DrawCore; deferring to DrawCore\");\n}","preventionTips":["Only call NewScoped*/transient allocation APIs inside DrawCore","Use persistent resource APIs for anything reused across frames","Review render feature lifecycle: Initialize/LoadContent must not allocate scoped resources"],"tags":["rendering","lifecycle","gpu-resources"],"backgroundTag":"unsupported-operation","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"}