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
- 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
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
- 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
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
- Cannot use a different context between Load and Draw
- A dependency object is already attached to this instance of…
- A dependency object must be attached in order to register a…
- A dependency object must be attached in order to unregister…
- A texture with size [ ] already exist with the same output…
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)