From 6ff4befb04002aca00a763c7e05cd9dbd2d97c0c Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 4 Dec 2024 22:00:56 +1000 Subject: [PATCH] Possible fix for tick watchdog hang --- .../kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt index 544451c7e8..f14bc83665 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt @@ -612,7 +612,7 @@ open class Pokemon : ShowdownIdentifiable { if (owner is LivingEntity) { owner.swing(InteractionHand.MAIN_HAND, true) val spawnDirection: Vec3 - val spawnYaw: Double + var spawnYaw: Double if (battleId != null) { // Look for an opposing opponent to face val battle = Cobblemon.battleRegistry.getBattle(battleId) @@ -640,6 +640,14 @@ open class Pokemon : ShowdownIdentifiable { spawnDirection = position.subtract(owner.position()) spawnYaw = atan2(spawnDirection.z, spawnDirection.x) * 180.0 / PI + 102.5 } + + // In some edge cases, I suspect we are producing NaN's here. This actually leads into a really big problem. + // Why? Because on tick, LivingEntity tries to bring rotations back within one loop around 0-360 using while loops. + // NaN resists arithmetic, so the while loops run forever and the server thread will hang trying to normalize + // this angle. Better to catch it here and correct it. Y'know. If this is actually the problem. I believe! + if (!spawnYaw.isFinite()) { + spawnYaw = 0.0 + } it.entityData.set(PokemonEntity.SPAWN_DIRECTION, spawnYaw.toFloat()) } if (owner != null) {