{"record":{"id":"4b25197ed0792d82","repo":"slint-ui/slint","slug":"it-must-be-there-because-we-set-the-global","errorCode":null,"errorMessage":"It must be there because we set the global","messagePattern":"It must be there because we set the global","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/core/window.rs","lineNumber":2129,"sourceCode":"            .borrow()\n            .iter()\n            .find(|p| ItemTreeRc::ptr_eq(&p.component, &parent_root_item_tree))\n        {\n            // Popup in a popup\n            match &parent_popup.location {\n                PopupWindowLocation::TopLevel(wa) => wa.clone(),\n                PopupWindowLocation::ChildWindow(_) => self.window_adapter(),\n            }\n        } else {\n            self.window_adapter()\n        };\n\n        let popup_window_adapter = {\n            let mut popup_window_adapter = None;\n            ItemTreeRc::borrow_pin(popup_componentrc)\n                .as_ref()\n                .window_adapter(false, &mut popup_window_adapter);\n            popup_window_adapter.expect(\"It must be there because we set the global\")\n        };\n\n        // If the window adapter of the popup window and the parent window are equal, create a ChildWindow\n        // because we weren't able to create a dedicated popup adapter (for example if the backend does not support it).\n        let (location, properties_tracker) =\n            if Rc::ptr_eq(&parent_window_adapter, &popup_window_adapter) {\n                // Tooltips may extend past the window (e.g. above/left of the anchor); do not clamp.\n                let clip_region = Some(LogicalRect::new(\n                    LogicalPoint::new(0.0 as crate::Coord, 0.0 as crate::Coord),\n                    self.window_adapter().size().to_logical(self.scale_factor()).to_euclid(),\n                ));\n                let rect = popup::place_popup(\n                    popup::Placement::Fixed(LogicalRect::new(position, size)),\n                    &clip_region,\n                );\n                self.window_adapter().request_redraw();\n                (\n                    PopupWindowLocation::ChildWindow(rect.origin),","sourceCodeStart":2111,"sourceCodeEnd":2147,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/core/window.rs#L2111-L2147","documentation":"During `show_popup`, after instantiating the popup component Slint calls `window_adapter(false, ...)` on the popup's item tree; because the global window adapter was already set on the popup tree at that point, the Option is expected to be Some. The expect fires if the popup's item tree has no window adapter — meaning the setup step that assigns the adapter to the popup component did not happen.","triggerScenarios":"Showing a popup when the popup component's item tree was created without being attached to a window adapter — e.g. manual popup instantiation through the interpreter/FFI bypassing the normal show_popup setup, or backend code constructing popups out of order.","commonSituations":"Custom backend/window-adapter development; interpreter-driven apps that create popup item trees directly instead of going through `show_popup`; race/ordering bugs in embedded backends without dedicated popup window support.","solutions":["Always show popups through the public API (`show_popup` / `PopupWindow`) so the window adapter is set on the popup tree first","When writing a custom backend, ensure `window_adapter(true, ...)` (or the global adapter assignment) runs on the popup item tree before this code path","Verify with a debug assert that the popup component was instantiated against the parent window's adapter"],"exampleFix":"// before\nlet tree = popup_def.create(&ctx)?; // never attached to a window adapter\nwindow.show_popup(&tree, ...); // panics\n// after\nlet tree = popup_def.create_with_window_adapter(&parent_adapter, &ctx)?;\nwindow.show_popup(&tree, ...);","handlingStrategy":"validation","validationCode":"// confirm the popup tree has a window adapter before showing\nlet mut adapter = None;\nItemTreeRc::borrow_pin(&popup_tree).as_ref().window_adapter(false, &mut adapter);\nassert!(adapter.is_some(), \"popup item tree has no window adapter\");","typeGuard":"fn popup_has_adapter(tree: &ItemTreeRc) -> bool {\n    let mut a = None;\n    ItemTreeRc::borrow_pin(tree).as_ref().window_adapter(false, &mut a);\n    a.is_some()\n}","tryCatchPattern":"std::panic::catch_unwind(AssertUnwindSafe(|| window.show_popup(&popup_tree, pos, true))).map_err(|_| PopupError::NoWindowAdapter)","preventionTips":["Show popups only through show_popup/PopupWindow, never with hand-built item trees","In custom backends, attach the window adapter to the popup tree before placement","Add a debug assertion checking adapter presence when instantiating popups"],"tags":["rust","panic","popup","window-adapter","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"3a7e700487dc74d404cad0726378053ab763d4e0","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}