stride3d/stride · critical · InvalidOperationException
Unable to find a GraphicsDevice instance
Error message
Unable to find a GraphicsDevice instance
What it means
After locating IGraphicsDeviceService in the GameBase constructor, it checks that the service actually exposes a non-null GraphicsDevice. A registered service with a null device means no real rendering device was created, so the constructor throws this InvalidOperationException.
Solutions
- Ensure the IGraphicsDeviceService creates/returns a valid GraphicsDevice before the Game constructor runs
- Verify GPU drivers and that the platform supports device creation
- In tests, mock a non-null GraphicsDevice or use Stride's headless abstractions
Example fix
// before
public class FakeService : IGraphicsDeviceService { public GraphicsDevice GraphicsDevice => null; }
// after
public class FakeService : IGraphicsDeviceService { public GraphicsDevice GraphicsDevice { get; } = CreateMockDevice(); } Defensive patterns
Strategy: validation
Validate before calling
if (services.GetService<IGraphicsDeviceService>()?.GraphicsDevice == null) throw new InvalidOperationException("GraphicsDevice not ready"); Type guard
bool HasDevice(IGraphicsDeviceService s) => s?.GraphicsDevice != null;
Try / catch
try { var game = new MyGame(); } catch (InvalidOperationException ex) when (ex.Message.Contains("GraphicsDevice instance")) { /* fix device creation, then retry */ } Prevention
- Ensure device creation completes before Game construction
- Validate GPU drivers/environment on target machines
- Never register stub services with null devices outside tests
When it happens
Trigger: A custom or stub IGraphicsDeviceService registered in Services whose GraphicsDevice property is null; device creation failing silently before Game construction; uninitialized custom device implementations.
Common situations: Test doubles returning null GraphicsDevice; custom device factories failing on machines without supported GPU/drivers; creating the service before the device is created.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- adapter
- Unable to create a IGraphicsDeviceService
- A overlaps with another element. Check the element's offset
- A region can only be specified for Textures with…
- AlphaLoadMode. not supported for the Stride image format…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/4444ff05cbc4f732.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Games/GameBase.cs:966
private void GamePlatform_Exiting(object sender, EventArgs e)
{
OnExiting(this, EventArgs.Empty);
}
private void SetupGraphicsDeviceEvents()
{
// Find the IGraphicsDeviceSerive.
graphicsDeviceService = Services.GetService<IGraphicsDeviceService>();
// If there is no graphics device service, don't go further as the whole Game would not work
if (graphicsDeviceService == null)
{
throw new InvalidOperationException("Unable to create a IGraphicsDeviceService");
}
if (graphicsDeviceService.GraphicsDevice == null)
{
throw new InvalidOperationException("Unable to find a GraphicsDevice instance");
}
resumeManager = new ResumeManager(Services);
GraphicsDevice = graphicsDeviceService.GraphicsDevice;
graphicsDeviceService.DeviceCreated += GraphicsDeviceService_DeviceCreated;
graphicsDeviceService.DeviceResetting += GraphicsDeviceService_DeviceResetting;
graphicsDeviceService.DeviceReset += GraphicsDeviceService_DeviceReset;
graphicsDeviceService.DeviceDisposing += GraphicsDeviceService_DeviceDisposing;
}
private void DisposeGraphicsDeviceEvents()
{
if (graphicsDeviceService != null)
{
graphicsDeviceService.DeviceCreated -= GraphicsDeviceService_DeviceCreated;
graphicsDeviceService.DeviceResetting -= GraphicsDeviceService_DeviceResetting;
graphicsDeviceService.DeviceReset -= GraphicsDeviceService_DeviceReset;View on GitHub (pinned to 96fad776d2)