You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting consistent “Fatal error: Array index is out of range” crashes in GradientNoise2D's evaluate(_ x:Double, _ y:Double) at gradient.swift on line 540.
The issue seems to be that the staticGradientNoise2D.points is initialized to have 32 members on line 354 , then when evaluate(…) is called, base_vertex_index:Int ends up with value of 32(Int((2*sample_uv_rel.y - sample_uv_rel.x - Double(a))*0.5 + 1) << 4 with sample_uv_rel = (1, 0) & a = 0 → Int((2*1 - 0 - Double(0))*0.5 + 1) << 4 → Int(2*0.5 + 1) << 4 → Int(2) << 4 → 32, on line 457).
Finally on line 540, the code attempts to iterate in a for loop over GradientNoise2D.points[base_vertex_index ..< base_vertex_index + 4]… so GradientNoise2D.points[32..<36] when GradientNoise2D.points is only 32 elements long.
I don't really know how this noise math is meant to work, so I can't speculate as to what a fix should be other than… missing modulus? IDK.
The text was updated successfully, but these errors were encountered:
capnslipp
added a commit
to capnslipp/metal-voxel-planet
that referenced
this issue
Mar 7, 2023
Fix for “Fatal error: Array index is out of range” crashes in `GradientNoise2D evaluate(_:Double,_:Double)`. Issue has already been reported at tayloraswift/swift-noise#11 , so this is just a workaround based on my limited understanding of how the noise generation works.
* Worked around crashes by running a modulus (division remainder) on the position before passing it to `noise.evaluate(…)`. Modulusing against a new `noisePeriod` (`20`) ivar, the reciprocal of the existing noise `frequency` (`0.05`).
BIG NOTE: Again, no idea if this is the correct math. The output voxel chunks look repeated, so it might not be. I'm not sure how else to fix it though.
Fix for “Fatal error: Array index is out of range” crashes in `GradientNoise2D evaluate(_:Double,_:Double)`. Issue has already been reported at tayloraswift/swift-noise#11 , so this is just a workaround based on my limited understanding of how the noise generation works.
* Worked around crashes by running a modulus (division remainder) on the position before passing it to `noise.evaluate(…)`. Modulusing against a new `noisePeriod` (`20`) ivar, the reciprocal of the existing noise `frequency` (`0.05`).
BIG NOTE: Again, no idea if this is the correct math. The output voxel chunks look repeated, so it might not be. I'm not sure how else to fix it though.
I'm getting consistent “Fatal error: Array index is out of range” crashes in
GradientNoise2D
'sevaluate(_ x:Double, _ y:Double)
at gradient.swift on line 540.The issue seems to be that the static
GradientNoise2D.points
is initialized to have 32 members on line 354 , then whenevaluate(…)
is called,base_vertex_index:Int
ends up with value of32
(Int((2*sample_uv_rel.y - sample_uv_rel.x - Double(a))*0.5 + 1) << 4
withsample_uv_rel = (1, 0)
&a = 0
→Int((2*1 - 0 - Double(0))*0.5 + 1) << 4
→Int(2*0.5 + 1) << 4
→Int(2) << 4
→32
, on line 457).Finally on line 540, the code attempts to iterate in a for loop over
GradientNoise2D.points[base_vertex_index ..< base_vertex_index + 4]
… soGradientNoise2D.points[32..<36]
whenGradientNoise2D.points
is only32
elements long.I don't really know how this noise math is meant to work, so I can't speculate as to what a fix should be other than… missing modulus? IDK.
The text was updated successfully, but these errors were encountered: