Skip to content

Commit fcd4429

Browse files
rustbasicemilk
authored andcommitted
Fix: panic when dragging window between monitors of different pixels_per_point (emilk#4868)
Fix: panic when dragging window between monitors of different pixels_per_point This will continue to help us as we develop `egui`. I hope you agree with my defense of `panic`. * Relate emilk#3959 * Relate emilk#4088 * Closes emilk#4178 * Closes emilk#4179 There is also a way to add log if necessary. ``` log::debug!("Anti-panic behavior occurs"); ``` --------- Co-authored-by: Emil Ernerfeldt <[email protected]>
1 parent 17f52d9 commit fcd4429

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

crates/egui/src/context.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,12 +2418,18 @@ impl Context {
24182418

24192419
self.write(|ctx| {
24202420
let tessellation_options = ctx.memory.options.tessellation_options;
2421-
let texture_atlas = ctx
2422-
.fonts
2423-
.get(&pixels_per_point.into())
2424-
.expect("tessellate called with a different pixels_per_point than the font atlas was created with. \
2425-
You should use egui::FullOutput::pixels_per_point when tessellating.")
2426-
.texture_atlas();
2421+
let texture_atlas = if let Some(fonts) = ctx.fonts.get(&pixels_per_point.into()) {
2422+
fonts.texture_atlas()
2423+
} else {
2424+
#[cfg(feature = "log")]
2425+
log::warn!("No font size matching {pixels_per_point} pixels per point found.");
2426+
ctx.fonts
2427+
.iter()
2428+
.next()
2429+
.expect("No fonts loaded")
2430+
.1
2431+
.texture_atlas()
2432+
};
24272433
let (font_tex_size, prepared_discs) = {
24282434
let atlas = texture_atlas.lock();
24292435
(atlas.size(), atlas.prepared_discs())

crates/egui/src/layers.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ impl PaintList {
153153
/// and then later setting it using `paint_list.set(idx, cr, frame);`.
154154
#[inline(always)]
155155
pub fn set(&mut self, idx: ShapeIdx, clip_rect: Rect, shape: Shape) {
156+
if self.0.len() <= idx.0 {
157+
#[cfg(feature = "log")]
158+
log::warn!("Index {} is out of bounds for PaintList", idx.0);
159+
return;
160+
}
161+
156162
self.0[idx.0] = ClippedShape { clip_rect, shape };
157163
}
158164

0 commit comments

Comments
 (0)