stride3d/stride · error · InvalidOperationException

The method execution path is not within a DrawCore operation

Error message

The method execution path is not within a DrawCore operation

What it means

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.

Solutions

  1. Move the NewScopedBuffer call into your RenderFeature's DrawCore (or Unload via PersistentResources for reusable buffers)
  2. For long-lived resources, use persistent allocations (e.g. PushPersistentResource / CreatePersistentResource) instead of scoped ones
  3. If you need data prepared outside draw, stage it in CPU-side buffers and create the scoped buffer inside DrawCore

Example fix

// before
public override void InitializeCore()
{
    var buf = NewScopedBuffer(data, 0, size); // throws: not in DrawCore
}
// after
protected override void DrawCore(RenderDrawContext context)
{
    var buf = NewScopedBuffer(data, 0, size);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!isInDrawCore)
    throw new InvalidOperationException("Allocate scoped resources only inside DrawCore.");

Try / catch

try
{
    var buf = NewScopedBuffer(data, 0, size);
}
catch (InvalidOperationException)
{
    Logger.Warning("Scoped allocation outside DrawCore; deferring to DrawCore");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/740b431547965c7e. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Rendering/Rendering/RendererCoreBase.cs:192

        /// <summary>
        /// Pushes a new scoped resource to the current Draw.
        /// </summary>
        /// <param name="resource">The scoped resource</param>
        /// <returns></returns>
        protected T PushScopedResource<T>(T resource) where T : GraphicsResource
        {
            scopedResources.Add(resource);
            return resource;
        }

        /// <summary>
        /// Checks that the current execution path is between a PreDraw/PostDraw sequence and throws and exception if not.
        /// </summary>
        protected void CheckIsInDrawCore()
        {
            if (!isInDrawCore)
            {
                throw new InvalidOperationException("The method execution path is not within a DrawCore operation");
            }
        }

        protected override void Destroy()
        {
            // If this instance is destroyed and not unload, force an unload before destryoing it completely
            if (Context != null)
            {
                Unload();
            }
            base.Destroy();
        }

        protected T ToLoadAndUnload<T>(T effect) where T : class, IGraphicsRendererCore
        {
            if (effect == null) throw new ArgumentNullException("effect");
            effect.Initialize(Context);
            subRenderersToUnload.Add(effect);

View on GitHub (pinned to 96fad776d2)