whosit reports: [test server] headanim can create "invalid" vectors with some look directions like vector.new(0,-mat ... #9083

Open
opened 2025-11-10 11:36:21 +01:00 by yourland-report · 2 comments

whosit reports a bug:

[test server] headanim can create "invalid" vectors with some look directions like vector.new(0,-math.pi/2,0)

Doing this will crash:
/eval futil.set_look_dir(me, vector.new(0,-math.pi/2,0))
WARNING: you won't be able to join the game with the account ever again until you fix the headanim math :D (or disable the mod :p)

2025-11-10 11:29:20: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'headanim' in callback environment_Step(): "Invalid float value for 'x' (NaN or infinity)"
2025-11-10 11:29:20: ERROR[Main]: stack traceback:
2025-11-10 11:29:20: ERROR[Main]: 	[C]: in function 'set_bone_override'
2025-11-10 11:29:20: ERROR[Main]: 	/home/yl/5.13.0/Yourland_test/mods/headanim/init.lua:12: in function 'func'
2025-11-10 11:29:20: ERROR[Main]: 	...ourland_test/bin/../builtin/profiler/instrumentation.lua:111: in function <...ourland_test/bin/../builtin/profiler/instrumentation.lua:104>
2025-11-10 11:29:20: ERROR[Main]: 	.../5.13.0/Yourland_test/bin/../builtin/common/register.lua:26: in function <.../5.13.0/Yourland_test/bin/../builtin/common/register.lua:12

Status:

# Server: version: 5.13.0-yl-test | game: Minetest Game | uptime: 1min 52s | max lag: 0.606s | clients (2/52): AliasAlreadyTaken, whosit
whosit reports a bug: [test server] headanim can create "invalid" vectors with some look directions like vector.new(0,-math.pi/2,0) Doing this will crash: `/eval futil.set_look_dir(me, vector.new(0,-math.pi/2,0))` WARNING: you won't be able to join the game with the account ever again until you fix the headanim math :D (or disable the mod :p) ```fortran 2025-11-10 11:29:20: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'headanim' in callback environment_Step(): "Invalid float value for 'x' (NaN or infinity)" 2025-11-10 11:29:20: ERROR[Main]: stack traceback: 2025-11-10 11:29:20: ERROR[Main]: [C]: in function 'set_bone_override' 2025-11-10 11:29:20: ERROR[Main]: /home/yl/5.13.0/Yourland_test/mods/headanim/init.lua:12: in function 'func' 2025-11-10 11:29:20: ERROR[Main]: ...ourland_test/bin/../builtin/profiler/instrumentation.lua:111: in function <...ourland_test/bin/../builtin/profiler/instrumentation.lua:104> 2025-11-10 11:29:20: ERROR[Main]: .../5.13.0/Yourland_test/bin/../builtin/common/register.lua:26: in function <.../5.13.0/Yourland_test/bin/../builtin/common/register.lua:12 ``` Status: ``` # Server: version: 5.13.0-yl-test | game: Minetest Game | uptime: 1min 52s | max lag: 0.606s | clients (2/52): AliasAlreadyTaken, whosit ```
AliasAlreadyTaken was assigned by yourland-report 2025-11-10 11:36:21 +01:00
Member

init.lua Lines 7 to 22 in 580816fb3a
local pname = player:get_player_name()
local ldeg = -player:get_look_vertical()
if (lastdir[pname] or 0) ~= ldeg then
lastdir[pname] = ldeg
player:set_bone_override("Head", {
position = {
vec = basepos,
absolute = true
},
rotation = {
vec = {x = ldeg, y = 0, z = 0},
interpolation = 0.09,
}
})
end

There isn't much math here...
So, I guess, you can get invalid value past the API (in this case via futil.set_look_dir() which I implemented myself :D), it gets stored and then the game breaks?

local pi = math.pi
function futil.set_look_dir(player, look_dir)
	local pitch = math.asin(-look_dir.y)
	local yaw = math.atan2(look_dir.z, look_dir.x)
	player:set_look_vertical(pitch)
	player:set_look_horizontal((yaw + 1.5 * pi) % (2.0 * pi))
end

In this case:
math.asin(math.pi/2) == NaN

(btw, this is the commit that adds these checks for vectors: 6ca9d75f0b)

https://gitea.your-land.de/your-land/headanim/src/commit/580816fb3a492d1ceca4e6cd2a1c0dc796e5c9f9/init.lua#L7-L22 There isn't much math here... So, I guess, you can get invalid value past the API (in this case via `futil.set_look_dir()` which I implemented myself :D), it gets stored and then the game breaks? ```lua local pi = math.pi function futil.set_look_dir(player, look_dir) local pitch = math.asin(-look_dir.y) local yaw = math.atan2(look_dir.z, look_dir.x) player:set_look_vertical(pitch) player:set_look_horizontal((yaw + 1.5 * pi) % (2.0 * pi)) end ``` In this case: `math.asin(math.pi/2) == NaN` (btw, this is the commit that adds these checks for vectors: https://github.com/luanti-org/luanti/commit/6ca9d75f0bacfe71a232be4f590cc4f5d15ed068)
Member

So it's partly fault of my set_look_dir implementation not checking if values are valid and partly fault of minetest API for just accepting them, then returning now "illegal" vectors? X)

Also, just doing with no mods (or on previous versions):
/eval me:set_look_vertical(1/0)
messes up the camera and nothing gets rendered.

So it's partly fault of my `set_look_dir` implementation not checking if values are valid and partly fault of minetest API for just accepting them, then returning now "illegal" vectors? X) Also, just doing with no mods (or on previous versions): `/eval me:set_look_vertical(1/0)` messes up the camera and nothing gets rendered.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: your-land/bugtracker#9083
No description provided.