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

don't try to draw empty meshes in wgpu #2782

Merged
merged 1 commit into from
Feb 4, 2025
Merged

Conversation

edwloef
Copy link
Contributor

@edwloef edwloef commented Feb 3, 2025

A mesh with empty indices doesn't have anything to draw, so skip drawing it.

Giving tiny-skia empty meshes to draw works fine, however the wgpu renderer crashes horribly. This prevents that crash.

closes #2774

Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

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

Thanks! Little nitpick.

wgpu/src/lib.rs Outdated
Comment on lines 560 to 562
if !mesh.indices().is_empty() {
let (layer, transformation) = self.layers.current_mut();
layer.draw_mesh(mesh, transformation);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if !mesh.indices().is_empty() {
let (layer, transformation) = self.layers.current_mut();
layer.draw_mesh(mesh, transformation);
}
if mesh.indices().is_empty() {
return;
}
let (layer, transformation) = self.layers.current_mut();
layer.draw_mesh(mesh, transformation);

@hecrj hecrj added this to the 0.14 milestone Feb 3, 2025
@hecrj hecrj added bug Something isn't working rendering wgpu fix labels Feb 3, 2025
@hecrj
Copy link
Member

hecrj commented Feb 3, 2025

Thinking about it a bit more. I think this is a check that should happen in user code.

We consider empty meshes invalid. The same way trying to draw an empty quad is invalid too. Or tessellating an empty path. Or a mesh with a number of indices that is not a multiple of 3.

Instead of checking every mesh, if your code can produce empty meshes, you should filter them out right there.

In any case, we can add a debug_assert! here to panic early in debug mode.

@edwloef
Copy link
Contributor Author

edwloef commented Feb 3, 2025

Sure, a debug assert also sounds reasonable. At least that would make the issue more easily debuggable

@hecrj hecrj enabled auto-merge February 4, 2025 00:22
@hecrj hecrj merged commit 3f509c6 into iced-rs:master Feb 4, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix rendering wgpu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rendering only empty meshes crashes iced
2 participants