Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egui-wgpu: Fix crash on zero-sized scissor rects #2039

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ pub trait App {
/// Can be used from web to interact or other external context
/// Implementation is needed, because downcasting Box<dyn App> -> Box<dyn Any> to get &ConcreteApp is not simple in current rust.
///
/// Just return &mut *self
/// Just copy-paste this as your implementation:
/// ```ignore
/// #[cfg(target_arch = "wasm32")]
/// fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
/// &mut *self
/// }
/// ```
Comment on lines +77 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe default implementation can be provided? Or it will return not right Any?

#[cfg(target_arch = "wasm32")]
fn as_any_mut(&mut self) -> &mut dyn Any;

Expand Down
15 changes: 6 additions & 9 deletions crates/egui-wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

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

let width = (clip_max_x - clip_min_x).at_least(1);
let height = (clip_max_y - clip_min_y).at_least(1);

ScissorRect {
Self {
x: clip_min_x,
y: clip_min_y,
width,
height,
width: clip_max_x - clip_min_x,
height: clip_max_y - clip_min_y,
}
}
}
Expand Down