{"record":{"id":"ca104e1003a6ab21","repo":"slint-ui/slint","slug":"context-menus-should-always-have-a-menu","errorCode":null,"errorMessage":"context menus should always have a menu","messagePattern":"context menus should always have a menu","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backends/winit/muda.rs","lineNumber":94,"sourceCode":"        context_menu: &vtable::VRc<MenuVTable>,\n        winit_window: &Window,\n        position: LogicalPosition,\n        proxy: EventLoopProxy<SlintEvent>,\n    ) -> Option<Self> {\n        install_event_handler_if_necessary(proxy);\n\n        let mut s = Self { entries: Default::default(), tracker: None, menu: None };\n        s.rebuild_menu(winit_window, Some(context_menu), MudaType::Context);\n\n        match winit_window.window_handle().ok()?.as_raw() {\n            #[cfg(target_os = \"windows\")]\n            RawWindowHandle::Win32(handle) => {\n                let position = i_slint_core::api::WindowPosition::Logical(position);\n                let position = crate::winitwindowadapter::position_to_winit(&position);\n                unsafe {\n                    s.menu\n                        .as_ref()\n                        .expect(\"context menus should always have a menu\")\n                        .show_context_menu_for_hwnd(handle.hwnd.get(), Some(position));\n                }\n                Some(s)\n            }\n            #[cfg(target_os = \"macos\")]\n            RawWindowHandle::AppKit(handle) => {\n                // muda assumes a non-flipped NSView and flips Y internally. But winit's view\n                // has isFlipped=true, so we pre-flip Y to compensate.\n                let h =\n                    winit_window.inner_size().to_logical::<f64>(winit_window.scale_factor()).height;\n                let position = Some(winit::dpi::Position::Logical(\n                    winit::dpi::LogicalPosition::new(position.x as f64, h - position.y as f64),\n                ));\n                unsafe {\n                    s.menu\n                        .as_ref()\n                        .expect(\"context menus should always have a menu\")\n                        .show_context_menu_for_nsview(handle.ns_view.as_ptr(), position)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/internal/backends/winit/muda.rs#L76-L112","documentation":"On Windows, `show_context_menu` displays the muda menu via `show_context_menu_for_hwnd`. The wrapper struct is built with a menu attached, so `menu` should never be `None` here; if it is, an internal invariant is broken and the code panics.","triggerScenarios":"Calling `Window::show_context_menu()` on Windows when the internal `muda::Menu` was not constructed or was taken before display - an internal state inconsistency.","commonSituations":"Library-internal inconsistency; misuse of internal menu wrappers; version mismatch between slint internals; a bug when the context menu setup failed silently earlier.","solutions":["Retry the call to confirm it is not a one-off setup race; ensure a valid menu/MenuItem list was passed","Check that you are not mixing slint-internal menu APIs with direct muda usage","Update to the latest slint version and report a bug with a reproducer if it persists"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| window.show_context_menu(position, &menu))\n    .map_err(|_| anyhow!(\"context menu display failed on this platform\"))?;","preventionTips":["Pass a fully built menu to show_context_menu each call","Keep slint crate versions consistent across the workspace","If it reproduces on Windows with a valid menu, file an upstream bug"],"tags":["winit","menus","windows","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}