stride3d/stride · critical · InvalidOperationException

Could not recreate all objects.

Error message

Could not recreate all objects.

What it means

ResumeManager.OnRecreate re-creates graphics resources after a device reset/context resume. If some resources were destroyed and could not be recreated, it throws InvalidOperationException with a 'DestroyedObjects' entry in Data listing the resources stuck in the Destroyed lifetime state.

Solutions

  1. Inspect the exception's Data["DestroyedObjects"] list to identify which resources failed to recreate
  2. Fix the recreation path of the failing resources (e.g. unsupported format/size after device reset)
  3. Dispose and rebuild the GraphicsDevice or reload the affected assets if resources cannot be restored
  4. Handle device-lost events gracefully so recreation retries with valid parameters

Example fix

// before
catch (InvalidOperationException) { /* ignored */ }
// after
catch (InvalidOperationException ex) when (ex.Data.Contains("DestroyedObjects"))
{
    var destroyed = (List<GraphicsResource>)ex.Data["DestroyedObjects"];
    foreach (var r in destroyed) r.Dispose();
    RecreateDeviceAndResources();
}
Defensive patterns

Strategy: try-catch

Try / catch

try { resumeManager.OnRecreate(); } catch (InvalidOperationException ex) when (ex.Data.Contains("DestroyedObjects")) { /* inspect ex.Data["DestroyedObjects"] and rebuild device */ }

Prevention

When it happens

Trigger: Calling OnRecreate (via OnRender) after a device lost/reset event when at least one registered graphics resource fails to recreate, leaving destroyed objects behind.

Common situations: GPU device removal/reset on mobile or after driver crash, resuming an app after system suspend, or window/backbuffer recreation where a resource's recreation logic fails (e.g. format no longer supported).

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Graphics/ResumeManager.cs:110

                            if (resource.OnRecreate())
                            {
                                wasSomethingRecreated = true;
                                resource.LifetimeState = GraphicsResourceLifetimeState.Active;
                            }
                            else
                            {
                                // Couldn't be recreated?
                                hasDestroyedObjects = true;
                            }
                        }
                    }
                }

                if (hasDestroyedObjects)
                {
                    // Attach the list of objects that could not be recreated to the exception.
                    var destroyedObjects = graphicsDevice.Resources.Where(x => x.LifetimeState == GraphicsResourceLifetimeState.Destroyed).ToList();
                    throw new InvalidOperationException("Could not recreate all objects.") { Data = { { "DestroyedObjects", destroyedObjects } } };
                }
            }
        }

        /// <summary>
        ///   Called when the Resume Manager is being destroyed.
        /// </summary>
        /// <param name="immediately">
        ///   A value indicating whether the resources used by the Resume Manager should be destroyed immediately
        ///   (<see langword="true"/>), or if it can be deferred until it's safe to do so (<see langword="false"/>).
        /// </param>
        public void OnDestroyed(bool immediately = false)
        {
            lock (graphicsDevice.Resources)
            {
                foreach (var resource in graphicsDevice.Resources)
                {
                    resource.OnDestroyed(immediately);

View on GitHub (pinned to 96fad776d2)