{"record":{"id":"f731f35737cbdb28","repo":"emilk/egui","slug":"single-use-appcreator-has-unexpectedly-already-bee-f731f3","errorCode":null,"errorMessage":"Single-use AppCreator has unexpectedly already been taken","messagePattern":"Single-use AppCreator has unexpectedly already been taken","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eframe/src/native/wgpu_integration.rs","lineNumber":314,"sourceCode":"\n        #[allow(clippy::allow_attributes, unused_mut)] // used for accesskit\n        let mut egui_winit = egui_winit::State::new(\n            egui_ctx.clone(),\n            ViewportId::ROOT,\n            event_loop,\n            Some(window.scale_factor() as f32),\n            event_loop.system_theme(),\n            painter.max_texture_side(),\n        );\n\n        #[cfg(feature = \"accesskit\")]\n        {\n            let event_loop_proxy = self.repaint_proxy.lock().clone();\n            egui_winit.init_accesskit(event_loop, &window, event_loop_proxy);\n        }\n\n        let app_creator = core::mem::take(&mut self.app_creator)\n            .expect(\"Single-use AppCreator has unexpectedly already been taken\");\n\n        crate::maybe_attach_inspection_plugin(&egui_ctx, Some(self.app_name.clone()));\n\n        let cc = CreationContext {\n            egui_ctx: egui_ctx.clone(),\n            integration_info: integration.frame.info().clone(),\n            storage: integration.frame.storage(),\n            #[cfg(feature = \"glow\")]\n            gl: None,\n            #[cfg(feature = \"glow\")]\n            get_proc_address: None,\n            wgpu_render_state,\n            window: Some(Arc::clone(&window)),\n            raw_display_handle: window.display_handle().map(|h| h.as_raw()),\n            raw_window_handle: window.window_handle().map(|h| h.as_raw()),\n        };\n        let app = {\n            profiling::scope!(\"user_app_creator\");","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/eframe/src/native/wgpu_integration.rs#L296-L332","documentation":"`app_creator` is a `Option<AppCreator>` consumed exactly once during startup: `init_run_state` does `core::mem::take(&mut self.app_creator)` and panics if it was already `None`. This enforces the single-use contract — the closure that builds your `App` must run exactly once when the first window/viewport initializes. Seeing this panic means `init_run_state` was entered twice (or the creator was taken elsewhere), which is an internal state machine violation.","triggerScenarios":"Calling `init_run_state` twice on the same `RunState`/integration (e.g. re-initializing after the event loop restarted), or a viewport-instantiation path that runs while a previous initialization already consumed the `AppCreator`.","commonSituations":"Custom multi-viewport setups where the app-creation hook fires twice; embedding eframe and manually restarting the event loop with the same options/state; forks or patched integrations that call init paths directly.","solutions":["Ensure `run_native`/`eframe::run_simple_native` is called once per process and the event loop is not restarted with reused state.","Create a fresh `NativeOptions` and let eframe construct its own run state instead of reusing or caching integration state.","In custom integrations, check that only one viewport initialization path calls `init_run_state`/consumes `app_creator`.","If using the wasm/web backend with hot-reload, make sure state isn't carried across reloads into a second init."],"exampleFix":"// before: reusing state across a manual event-loop restart\nlet mut state = RunState::new(options, app_creator);\n// ... later, with the same state\nstate.init_run_state(&event_loop)?; // panics if already taken\n// after: build a fresh run state each time you start an event loop\nlet mut state = RunState::new(fresh_options, app_creator);\nstate.init_run_state(&event_loop)?;","handlingStrategy":"validation","validationCode":"// Ensure the creator is still available before re-running init\nfn ensure_creator(state: &RunState) -> Result<(), String> {\n    if state.app_creator.is_none() {\n        return Err(\"AppCreator already consumed; build a fresh RunState\".into());\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call run_native once per process; never reuse RunState/NativeOptions across event-loop restarts","Let eframe own initialization instead of calling init_run_state manually","Recreate all state when restarting the event loop (e.g. after wasm reload)"],"tags":["panic","eframe","app-creator","initialization","single-use"],"backgroundTag":"invalid-state-transition","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}