{"record":{"id":"cc50fce27188b8d5","repo":"FyroxEngine/Fyrox","slug":"graphics-context-is-uninitialized","errorCode":null,"errorMessage":"Graphics context is uninitialized!","messagePattern":"Graphics context is uninitialized!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-impl/src/engine/mod.rs","lineNumber":284,"sourceCode":"/// with which it was created and some of the main window parameters (position, size, etc.) and will re-use these\n/// parameters on a next initialization attempt.\n#[allow(clippy::large_enum_variant)]\npub enum GraphicsContext {\n    /// Fully initialized graphics context. See [`InitializedGraphicsContext`] docs for more info.\n    Initialized(InitializedGraphicsContext),\n\n    /// Uninitialized (suspended) graphics context. See [`GraphicsContextParams`] docs for more info.\n    Uninitialized(GraphicsContextParams),\n}\n\nimpl GraphicsContext {\n    /// Attempts to cast a graphics context to its initialized version. The method will panic if the context\n    /// is not initialized.\n    pub fn as_initialized_ref(&self) -> &InitializedGraphicsContext {\n        if let GraphicsContext::Initialized(ctx) = self {\n            ctx\n        } else {\n            panic!(\"Graphics context is uninitialized!\")\n        }\n    }\n\n    /// Attempts to cast a graphics context to its initialized version. The method will panic if the context\n    /// is not initialized.\n    pub fn as_initialized_mut(&mut self) -> &mut InitializedGraphicsContext {\n        if let GraphicsContext::Initialized(ctx) = self {\n            ctx\n        } else {\n            panic!(\"Graphics context is uninitialized!\")\n        }\n    }\n}\n\npub(crate) enum GameErrorSource {\n    PluginMethod(&'static str),\n    ScriptMethod {\n        scene_handle: Handle<Scene>,","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-impl/src/engine/mod.rs#L266-L302","documentation":"as_initialized_ref() attempts to narrow a GraphicsContext enum to its Initialized variant and returns a reference to the initialized context. If the context is still Uninitialized (no window/renderer created yet), the method panics instead of returning a reference.","triggerScenarios":"Calling engine.get_graphics_context().as_initialized_ref() before Engine::initialize created the graphics context, or after it was set to Uninitialized (e.g. context destroyed).","commonSituations":"Accessing the renderer in Plugin::init or first frame before context creation; headless/CI runs without a display where the context never initializes; code assuming the context is always initialized.","solutions":["Only call as_initialized_ref after the context is confirmed Initialized","Match on GraphicsContext::Initialized yourself instead of force-casting","Defer renderer access to Plugin::update where the context exists"],"exampleFix":"// before\nlet ctx = engine.get_graphics_context().as_initialized_ref();\n// after\nif let GraphicsContext::Initialized(ctx) = engine.get_graphics_context() {\n    // use ctx.renderer\n}","handlingStrategy":"type-guard","validationCode":"let ready = matches!(engine.get_graphics_context(), GraphicsContext::Initialized(_));","typeGuard":"fn initialized(ctx: &GraphicsContext) -> Option<&InitializedGraphicsContext> { if let GraphicsContext::Initialized(c) = ctx { Some(c) } else { None } }","tryCatchPattern":"std::panic::catch_unwind(|| ctx.as_initialized_ref()) // prefer if-let instead","preventionTips":["Never touch the renderer before initialization completes","Match on GraphicsContext instead of using *_ref/*_mut panicking helpers","Handle headless (context-less) runs explicitly"],"tags":["graphics","state","panic","fyrox"],"backgroundTag":"invalid-state-transition","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}