Skip to content

Commit

Permalink
Workaround to avoid full hang (#589)
Browse files Browse the repository at this point in the history
As the scale factor becomes unreasonably large, the number of
subdivisions of an Euler spiral into lines grows, making the flatten
stage take too long.

This patch just bounds the number of subdivisions, so it will eventually
make progress. It will be slow, but not hang.

A better solution would be to aggressively cull so it only generates
geometry inside the viewport, but that is considerably more complicated.

Workaround for #548
  • Loading branch information
raphlinus authored May 30, 2024
1 parent 3842b3d commit 4cace9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/shaders/src/cpu/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ fn flatten_euler(
let n_frac = scaled_int;
(n_frac, EspcRobust::Normal)
};
let n = (n_frac * scale_multiplier).ceil().max(1.0);
let n = (n_frac * scale_multiplier).ceil().clamp(1.0, 100.0);

// Flatten line segments
log!("@@@ loop: lines: {n}");
Expand Down
5 changes: 4 additions & 1 deletion shader/flatten.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,10 @@ fn flatten_euler(
let integrand_peak = sqrt(abs(k_peak * (k_peak * dist_scaled + 1.0)));
n_frac = integral * integrand_peak / a;
}
let n = max(ceil(n_frac * scale_multiplier), 1.0);
// Bound number of subdivisions to a reasonable number when the scale is huge.
// This may give slightly incorrect rendering but avoids hangs.
// TODO: aggressively cull to viewport
let n = clamp(ceil(n_frac * scale_multiplier), 1.0, 100.0);
for (var i = 0u; i < u32(n); i++) {
var lp1: vec2f;
if i + 1u == u32(n) && t1 == 1.0 {
Expand Down

0 comments on commit 4cace9d

Please sign in to comment.