Skip to content

Commit c5495d6

Browse files
authored
egui-wgpu: Fix crash on zero-sized scissor rects (#2039)
1 parent 2842d39 commit c5495d6

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

crates/eframe/src/epi.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ pub trait App {
7474
/// Can be used from web to interact or other external context
7575
/// Implementation is needed, because downcasting Box<dyn App> -> Box<dyn Any> to get &ConcreteApp is not simple in current rust.
7676
///
77-
/// Just return &mut *self
77+
/// Just copy-paste this as your implementation:
78+
/// ```ignore
79+
/// #[cfg(target_arch = "wasm32")]
80+
/// fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
81+
/// &mut *self
82+
/// }
83+
/// ```
7884
#[cfg(target_arch = "wasm32")]
7985
fn as_any_mut(&mut self) -> &mut dyn Any;
8086

crates/egui-wgpu/src/renderer.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::{borrow::Cow, collections::HashMap, num::NonZeroU32};
44

5-
use egui::{epaint::Primitive, NumExt, PaintCallbackInfo};
5+
use egui::{epaint::Primitive, PaintCallbackInfo};
66
use type_map::concurrent::TypeMap;
77
use wgpu;
88
use wgpu::util::DeviceExt as _;
@@ -405,9 +405,9 @@ impl Renderer {
405405
let rect = ScissorRect::new(clip_rect, pixels_per_point, size_in_pixels);
406406

407407
if rect.width == 0 || rect.height == 0 {
408-
// Skip rendering with zero-sized clip areas.
408+
// Skip rendering zero-sized clip areas.
409409
if let Primitive::Mesh(_) = primitive {
410-
// If this is a mesh, we need to advance the index and vertex buffer iterators
410+
// If this is a mesh, we need to advance the index and vertex buffer iterators:
411411
index_buffers.next().unwrap();
412412
vertex_buffers.next().unwrap();
413413
}
@@ -906,14 +906,11 @@ impl ScissorRect {
906906
let clip_max_x = clip_max_x.clamp(clip_min_x, target_size[0]);
907907
let clip_max_y = clip_max_y.clamp(clip_min_y, target_size[1]);
908908

909-
let width = (clip_max_x - clip_min_x).at_least(1);
910-
let height = (clip_max_y - clip_min_y).at_least(1);
911-
912-
ScissorRect {
909+
Self {
913910
x: clip_min_x,
914911
y: clip_min_y,
915-
width,
916-
height,
912+
width: clip_max_x - clip_min_x,
913+
height: clip_max_y - clip_min_y,
917914
}
918915
}
919916
}

0 commit comments

Comments
 (0)