iced-rs/iced · error

Compositor must be initialized

Error message

Compositor must be initialized

What it means

Panic from `compositor.as_mut().expect("Compositor must be initialized")` when inserting a new window into window_manager. The code guarantees the compositor was created in the block above (or a Crash control message was sent and the loop continued), so None here signals an internal invariant violation.

Source

Thrown at winit/src/lib.rs:630

                }

                let window_theme = window
                    .theme()
                    .map(conversion::theme_mode)
                    .unwrap_or_default();

                if system_theme != window_theme {
                    system_theme = window_theme;

                    runtime.broadcast(subscription::Event::SystemThemeChanged(window_theme));
                }

                let is_first = window_manager.is_empty();
                let window = window_manager.insert(
                    id,
                    window,
                    &program,
                    compositor.as_mut().expect("Compositor must be initialized"),
                    proxy.clone(),
                    renderer_settings,
                    exit_on_close_request,
                    system_theme,
                );

                window
                    .raw
                    .set_theme(conversion::window_theme(window.state.theme_mode()));

                debug::theme_changed(|| {
                    if is_first {
                        theme::Base::seed(window.state.theme())
                    } else {
                        None
                    }
                });

View on GitHub (pinned to d146509d89)

Solutions

  1. Do not modify the Control::Crash handling — keep the `continue` so insertion is skipped
  2. Update to upstream iced
  3. If forking, replace the expect with proper error propagation to Control::Crash

Example fix

// before
let window = window_manager.insert(id, window, &program, compositor.as_mut().expect("Compositor must be initialized"), ...);
// after
let Some(compositor) = compositor.as_mut() else { let _ = control_sender.start_send(Control::Crash("compositor missing".into())); continue; };
let window = window_manager.insert(id, window, &program, compositor, ...);
Defensive patterns

Strategy: type-guard

Validate before calling

// if forking: check compositor.is_some() before inserting the window

Type guard

let Some(compositor) = compositor.as_mut() else { return; };

Prevention

When it happens

Trigger: The Event::WindowCreated branch falls through to window_manager.insert with compositor still None — only possible if the compositor-creation block was skipped or a future refactor sends Crash without `continue`, or the oneshot handshake failed silently.

Common situations: Patched/forked iced code where the `continue` after Control::Crash was removed; exotic backends where compositor creation returns Err and control flow diverges.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of iced-rs/iced@d146509d89 (2026-09-11). Data as JSON: /api/errors/e10031b1231b4d7c. Report an issue: GitHub.