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

Assert dimensions of quads are normal in iced_tiny_skia #2082

Merged
merged 2 commits into from
Jan 31, 2024

Conversation

joshuamegnauth54
Copy link
Contributor

@joshuamegnauth54 joshuamegnauth54 commented Sep 14, 2023

Fixes #2066.

Iced may produce primitives with an infinite length or width. The WGPU renderer handles those somewhere along the pipeline. Tiny Skia's PathBuilder::finish returns None if non-normal floats are passed to the builder. This patch adds a check to prevent that.

I only fixed the immediate issue since it didn't seem like the other primitives needed the check. Plus, I didn't want to preemptively add checks where they're not needed. Let me know if I should make any changes.

See:

@@ -154,7 +154,26 @@ impl Backend {
border_width,
border_color,
} => {
let physical_bounds = (*bounds + translation) * scale_factor;
// Tiny Skia's `PathBuilder::finish` returns `None` on infinites and NaNs which causes iced to panic.
// Certain widget combinations can lead to an infinite in either dimension hence the need for this check.
Copy link
Member

Choose a reason for hiding this comment

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

What kind of valid widget combinations could lead to an infinite quad? It's important we don't try to fix invalid use cases.

Copy link
Contributor Author

@joshuamegnauth54 joshuamegnauth54 Sep 15, 2023

Choose a reason for hiding this comment

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

That's a good point! I mainly tried to fix the panic as reported in #2066, but the code is likely wrong since the submitter is sticking a TextInput into a Scrollable which is what directly leads to the panic. It also doesn't do what they want it do.

With that said, the WGPU renderer doesn't panic whereas the Tiny Skia renderer panics when it unwraps None. The message confused the submitter as mentioned in their original issue since it doesn't say anything about what caused the panic.

Would it make sense to merge this so neither renderer panics? Or should the Tiny Skia renderer still panic for the incorrect code?

Edit:

I think guarding the check so that it only applies in debug builds may be a better idea than what I submitted so far because:

  1. It's likely that the programmer(s) are working with debug builds when they make the mistake that would lead to the panic
  2. Tiny Skia panicking while WGPU doesn't is possibly confusing
  3. Having that check in release mode for every quad drawn is needlessly expensive, especially considering the code at hand is likely incorrect

@hecrj hecrj added this to the 0.12 milestone Jan 31, 2024
@hecrj hecrj force-pushed the issue2066 branch 2 times, most recently from 26b200c to 1004863 Compare January 31, 2024 20:04
@hecrj hecrj changed the title [Issue 2066] Fix Tiny Skia panic on infinite length quads @hecrj Assert dimensions of quads are normal in iced_tiny_skia Jan 31, 2024
@hecrj hecrj changed the title @hecrj Assert dimensions of quads are normal in iced_tiny_skia Assert dimensions of quads are normal in iced_tiny_skia Jan 31, 2024
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.

I just changed this to a debug_assert! with a more descriptive message, since it's just a case with an invalid primitive.

Thanks! 🙇

@hecrj hecrj enabled auto-merge January 31, 2024 20:12
@hecrj hecrj merged commit 6bf34b0 into iced-rs:master Jan 31, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Skia panicing rendering widgets
2 participants