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

Fix crash in gradient sampling #3828

Closed
wants to merge 1 commit into from

Conversation

frozolotl
Copy link
Contributor

@frozolotl frozolotl commented Mar 29, 2024

Closes #3826.

CC: @Dherse

@laurmaedje laurmaedje changed the title Fix #3826 Fix crash in gradient sampling Apr 1, 2024
@@ -1249,7 +1249,11 @@ fn sample_stops(stops: &[(Color, Ratio)], mixing_space: ColorSpace, t: f64) -> C

let (col_0, pos_0) = stops[low - 1];
let (col_1, pos_1) = stops[low];
let t = (t - pos_0.get()) / (pos_1.get() - pos_0.get());
let mut delta = pos_1.get() - pos_0.get();
if delta == 0.0 {
Copy link
Member

Choose a reason for hiding this comment

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

can we get into trouble if delta isn't equal to 0.0, but very close to it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The current way this is dealt with seems somewhat arbitrary to me. Wouldn't it make more sense to simply make t either 0.0, 0.5 or 1.0 in the event that two stops are the same?

Maybe I misunderstand what's going on though.

Copy link
Member

@laurmaedje laurmaedje Apr 8, 2024

Choose a reason for hiding this comment

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

I agree. As-is it behaves as if the two stops were actually very far apart (the full 100% = 1.0) and which of the stops "wins" depends on where the stops are along the gradient.

@laurmaedje laurmaedje added the waiting-on-author Pull request waits on author label Apr 8, 2024
@Enivex
Copy link
Collaborator

Enivex commented Apr 8, 2024

if delta == 0.0 {
delta = 1.0;
}
let t = (t - pos_0.get()) / delta;
Copy link
Member

Choose a reason for hiding this comment

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

We can also deduplicate stops beforehand, but I think we should in any case clamp t to 0.0..=1.0 here. You never know what's gonna happen with floats.

@laurmaedje
Copy link
Member

@frozolotl still on your radar?

@laurmaedje
Copy link
Member

Closing due to inactivity. Feel free to reopen if you still want to work on this!

@laurmaedje laurmaedje closed this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-on-author Pull request waits on author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Second stop at 0% in gradient crashes compiler in web app
3 participants