{"record":{"id":"73d27f4ac44ec17b","repo":"stride3d/stride","slug":"unexpected-null-graphicsdevice","errorCode":null,"errorMessage":"Unexpected null GraphicsDevice","messagePattern":"Unexpected null GraphicsDevice","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Games/GraphicsDeviceManager.cs","lineNumber":1243,"sourceCode":"                                GraphicsDevice.Presenter.Resize(newWidth, newHeight, newFormat);\n\n                                // Change full screen if needed\n                                GraphicsDevice.Presenter.IsFullScreen = graphicsDeviceInformation.PresentationParameters.IsFullScreen;\n\n                                needToCreateNewDevice = false;\n                            }\n                            catch { /* Ignore any exception */ }\n                        }\n                    }\n\n                    // If we still need to create a device, then we need to create it\n                    if (needToCreateNewDevice)\n                    {\n                        CreateDevice(graphicsDeviceInformation);\n                    }\n\n                    if (GraphicsDevice is null)\n                        throw new InvalidOperationException(\"Unexpected null GraphicsDevice\");\n\n                    var presentationParameters = GraphicsDevice.Presenter.Description;\n                    isReallyFullScreen = presentationParameters.IsFullScreen;\n\n                    if (presentationParameters.BackBufferWidth != 0)\n                        width = presentationParameters.BackBufferWidth;\n                    if (presentationParameters.BackBufferHeight != 0)\n                        height = presentationParameters.BackBufferHeight;\n                    deviceSettingsChanged = false;\n                }\n                finally\n                {\n                    // Notify the game Window that the screen device change is over\n                    if (isBeginScreenDeviceChange)\n                    {\n                        game.Window.EndScreenDeviceChange(width, height);\n                        game.Window.SetIsReallyFullscreen(isReallyFullScreen);\n                    }","sourceCodeStart":1225,"sourceCodeEnd":1261,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Games/GraphicsDeviceManager.cs#L1225-L1261","documentation":"After GraphicsDeviceManager attempts to create the device (CreateDevice), it validates that the GraphicsDevice property is non-null before reading presentation parameters; a null here means device creation silently failed to assign the device, violating an internal invariant. This is a defensive check surfaced when CreateDevice or the factory path did not actually produce a device.","triggerScenarios":"Code path in GraphicsDeviceManager (e.g. changing device/fullscreen toggling) sets needToCreateNewDevice and calls CreateDevice, yet GraphicsDevice remains null afterwards — e.g. CreateDevice's factory returned without constructing the device, or a prior creation failure was swallowed.","commonSituations":"Custom IGraphicsDeviceFactory implementations that don't set the device, partially failed device creation with earlier exceptions caught upstream, race conditions during window creation/ recreation, or platform factory mismatches.","solutions":["Inspect earlier logs/inner exceptions: fix the underlying CreateDevice/IGraphicsDeviceFactory failure so it actually produces a GraphicsDevice.","Ensure a stock factory (e.g. DeviceFactorySDL / platform default) is registered rather than a custom stub that returns without creating a device.","Update Stride — this null state can result from platform bugs fixed in later versions."],"exampleFix":"// before\npublic class MyFactory : IGraphicsDeviceFactory // never assigns GraphicsDevice\n// after\n// use the platform factory:\ngame.Services.AddService<IGraphicsDeviceFactory>(new DeviceFactorySDL());","handlingStrategy":"try-catch","validationCode":"if (game.Services.GetService<IGraphicsDeviceFactory>() is not DeviceFactorySDL && customFactory is null)\n    throw new InvalidOperationException(\"Register a real IGraphicsDeviceFactory\");","typeGuard":"bool DeviceCreated(GameBase g) => g.GraphicsDevice != null;","tryCatchPattern":"try { gdm.ApplyChanges(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unexpected null GraphicsDevice\"))\n{\n    logger.LogError(ex, \"Device creation did not produce a GraphicsDevice\");\n    throw;\n}","preventionTips":["Use stock platform factories instead of custom stubs.","Check CreateDevice inner exceptions/logs rather than swallowing them.","Keep Stride updated for platform device-creation fixes."],"tags":["graphics","null-reference","device-creation"],"backgroundTag":"internal-invariant-violation","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"}