emilk/egui · error
A style should be set for {:?}
Error message
A style should be set for {:?} What it means
`Themes::get::<S>()` fetches a widget style (`ThemeWrap<S>`) previously stored via the corresponding `set`. It reads from egui's temp memory keyed by the widget-style type; if no style for type `S` was ever set (or memory was cleared/reset between frames), the lookup returns None and it panics with the type name.
Source
Thrown at crates/egui/src/theme/themes.rs:51
if !force
&& self
.themes
.get_temp::<ThemeWrap<S>>(Id::NULL)
.is_some_and(|t| t.lock().type_id() == theme.type_id())
{
return;
}
self.themes
.insert_temp::<ThemeWrap<S>>(Id::NULL, Arc::new(Mutex::new(Box::new(theme))));
}
/// Fetch the style of the current theme
pub fn get<S: WidgetStyle + 'static>(&self) -> ThemeWrap<S> {
let v = self.themes.get_temp::<ThemeWrap<S>>(Id::NULL);
v.unwrap_or_else(|| {
panic!(
"A style should be set for {:?}",
core::any::type_name::<S>()
)
})
}
}
View on GitHub (pinned to 441971a776)
Solutions
- Call the matching `themes.set::<MyWidgetStyle>(ThemeWrap::new(...))` before any `get`.
- Use the non-panicking lookup (`get_temp` / an `opt` variant) and fall back to a default style when None.
- Ensure the `set` runs on the same Context/Themes instance and every frame (temp memory is per-frame for non-persisted temps).
- In tests, run the same style-initialization code path as the app before exercising widgets that call `get`.
Example fix
// before let style = themes.get::<ButtonStyle>(); // panics if never set // after themes.set::<ButtonStyle>(ThemeWrap::new(ButtonStyle::default())); let style = themes.get::<ButtonStyle>();
Defensive patterns
Strategy: fallback
Validate before calling
// ensure style exists before get
if !themes.is_set::<ButtonStyle>() {
themes.set::<ButtonStyle>(ThemeWrap::new(ButtonStyle::default()));
} Type guard
fn style_is_set<S: WidgetStyle + 'static>(themes: &Themes) -> bool {
themes.get_temp::<ThemeWrap<S>>(Id::NULL).is_some() // or the crate's opt accessor
} Prevention
- Always call themes.set::<S>(...) during app/Context initialization, unconditionally.
- Fall back to S::default() when the style lookup returns None instead of using the panicking get.
- Re-run style setup whenever egui memory may be reset (new Context, tests, memory clears).
- Cover style initialization in integration tests so a missing set fails early.
When it happens
Trigger: Calling `themes.get::<MyWidgetStyle>()` before ever calling `themes.set::<MyWidgetStyle>(...)`, or after egui memory was reset (e.g. `ctx.memory` clear / new Context instance), so `get_temp::<ThemeWrap<S>>(Id::NULL)` yields None.
Common situations: Setting theme styles in one place of the app (e.g. on startup with a feature flag) but reading them unconditionally elsewhere; tests creating a fresh Context without running the set-up path; forgetting the set call after refactoring.
Related errors
- Failed to find {:?} in Style::text_styles. Available styles:
- Failed to save screenshot to {path:?}: {err}
- Failed to create staging buffer for index data. Index count:
- Failed to create staging buffer for vertex data. Vertex coun
- Plugin of type {:?} not found
AI-assisted analysis of emilk/egui@441971a776 (2026-09-12).
Data as JSON: /api/errors/81f3c6402a878820.
Report an issue: GitHub.