Skip to content

Commit

Permalink
Workaround to avoid full hang
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 committed May 29, 2024
1 parent ba855c5 commit 6407a3d
Show file tree
Hide file tree
Showing 2 changed files with 2 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
2 changes: 1 addition & 1 deletion shader/flatten.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ 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);
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 6407a3d

Please sign in to comment.