Add a safeguard to a potentially-infinite loop
This commit is contained in:
parent
5e97ff8eca
commit
a4642c0e9f
|
|
@ -137,12 +137,12 @@ fn rand_float(state: ptr<function, u32>) -> f32 {
|
|||
}
|
||||
|
||||
fn rand_sphere(state: ptr<function, u32>) -> vec3f {
|
||||
loop {
|
||||
for (var k = 0; k < 16; k++) {
|
||||
let v = vec3f(rand_float(state), rand_float(state), rand_float(state)) - 0.5;
|
||||
let l = length(v);
|
||||
if (length(v) <= 0.5) {
|
||||
return v / l;
|
||||
}
|
||||
}
|
||||
return vec3f(0.0); // unreachable
|
||||
return vec3f(0.0); // safeguard
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user