clarify the StackOverflow catch in SectionOcclusion::floodFill

This commit is contained in:
Moritz Zwerger 2025-03-06 00:19:00 +01:00
parent 97e6cd11cf
commit 8f1247d4b1
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 13 additions and 8 deletions

View File

@ -14,9 +14,11 @@
package de.bixilon.minosoft.data.direction
import de.bixilon.minosoft.data.Axes
import de.bixilon.minosoft.data.text.formatting.TextFormattable
import de.bixilon.minosoft.util.KUtil.format
@JvmInline
value class DirectionVector private constructor(val value: Int) {
value class DirectionVector private constructor(val value: Int) : TextFormattable {
constructor() : this(0)
inline val x: Int get() = Integer.signum((value and (MASK shl SHIFT_X)) shl (Int.SIZE_BITS - SHIFT_X - BITS))
@ -41,6 +43,12 @@ value class DirectionVector private constructor(val value: Int) {
return DirectionVector(without or (value shl shift))
}
inline operator fun component1() = x
inline operator fun component2() = y
inline operator fun component3() = z
override fun toText() = "(${this.x.format()} ${this.y.format()} ${this.z.format()})"
override fun toString() = "v($x $y $z)"
companion object {
const val BITS = 2

View File

@ -55,13 +55,10 @@ class SectionOcclusion(
val regions = floodFill(array)
update(calculateOcclusion(regions), notify)
} catch (error: StackOverflowError) {
try {
val regions = floodFill(array)
update(calculateOcclusion(regions), notify)
} catch (error: StackOverflowError) {
println("Error: ${provider.section.chunk.position}; h=${provider.section.height} (ss=${error.stackTrace.size})")
error.printStackTrace()
}
// TODO: This is really stupid. The stack is large enough and still at some rare moments the method is crashing with an StackOverflow error.
// BUT: When running the EXACT same code again, it magically works and does not crash with an error. Stupid JVM.
val regions = floodFill(array)
update(calculateOcclusion(regions), notify)
} finally {
ALLOCATOR.free(array)
}