Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to index nil value caused by nodes with invalid param2 #610

Closed
debagos opened this issue Apr 30, 2022 · 8 comments · Fixed by #623
Closed

Attempt to index nil value caused by nodes with invalid param2 #610

debagos opened this issue Apr 30, 2022 · 8 comments · Fixed by #623

Comments

@debagos
Copy link

debagos commented Apr 30, 2022

I use the latest master on Minetest 5.5.0

ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'wielded_light' in callback environment_Step(): ...minetest-5.5.0/bin/../mods/mesecons/mesecons/presets.lua:67: attempt to index local 'dir' (a nil value)
ERROR[Main]: stack traceback:
ERROR[Main]: 	...minetest-5.5.0/bin/../mods/mesecons/mesecons/presets.lua:67: in function 'get_any_inputrules'
ERROR[Main]: 	...inetest-5.5.0/bin/../mods/mesecons/mesecons/internal.lua:97: in function 'get_any_rules'
ERROR[Main]: 	...etest-5.5.0/bin/../mods/mesecons/mesecons_wires/init.lua:81: in function <...etest-5.5.0/bin/../mods/mesecons/mesecons_wires/init.lua:67>
ERROR[Main]: 	...test-5.5.0/bin/../mods/mesecons/mesecons/actionqueue.lua:137: in function 'execute'
ERROR[Main]: 	...test-5.5.0/bin/../mods/mesecons/mesecons/actionqueue.lua:111: in function <...test-5.5.0/bin/../mods/mesecons/mesecons/actionqueue.lua:73>
ERROR[Main]: 	...i/github/minetest-5.5.0/bin/../builtin/game/register.lua:425: in function <...i/github/minetest-5.5.0/bin/../builtin/game/register.lua:409>

I have no clue what went wrong or how to reproduce it...
And keep in mind that 'wielded_light' is blamed wrongfully here: #609
The 'wielded_light' mod has no variable called "dir", but https://github.com/minetest-mods/mesecons/blob/master/mesecons/presets.lua#L66 does.

@TurkeyMcMac
Copy link
Contributor

This is probably due to an invalid param2 value on a node whose paramtype2 is facedir or wallmounted. If paramtype2 is facedir, then it must hold that param2 % 32 < 24. If paramtype2 is wallmounted, then it must hold that param2 % 8 < 6.

Possible culprits are buttons, levers, solar panels, and wall-mounted lamps. There may be others depending on what other mods you have that use Mesecons.

@debagos
Copy link
Author

debagos commented May 5, 2022

Server crashed again, just a few moments ago.

ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'wielded_light' in callback environment_Step(): ...minetest-5.5.0/bin/../mods/mesecons/mesecons/presets.lua:67: attempt to index local 'dir' (a nil value)
ERROR[Main]: stack traceback:
ERROR[Main]: 	...minetest-5.5.0/bin/../mods/mesecons/mesecons/presets.lua:67: in function 'get_any_inputrules'
ERROR[Main]: 	...inetest-5.5.0/bin/../mods/mesecons/mesecons/internal.lua:97: in function 'get_any_rules'
ERROR[Main]: 	...etest-5.5.0/bin/../mods/mesecons/mesecons_wires/init.lua:81: in function <...etest-5.5.0/bin/../mods/mesecons/mesecons_wires/init.lua:67>
ERROR[Main]: 	...test-5.5.0/bin/../mods/mesecons/mesecons/actionqueue.lua:137: in function 'execute'
ERROR[Main]: 	...test-5.5.0/bin/../mods/mesecons/mesecons/actionqueue.lua:111: in function <...test-5.5.0/bin/../mods/mesecons/mesecons/actionqueue.lua:73>
ERROR[Main]: 	...i/github/minetest-5.5.0/bin/../builtin/game/register.lua:425: in function <...i/github/minetest-5.5.0/bin/../builtin/game/register.lua:409>

I discovered something interesting, everytime this crash happens, a player digs this node: homedecor:glowlight_small_cube_14 and there are two mentions in the homedecor_lighting init.lua of the mesecon.rules.wallmounted_get function, which internally calls the rules_from_dir, which then attempts to index hte parameter 2 (dir) with no data/nil.
So I guess this issued should be closed an reopened in the homedecor repository.
If you have some idea how I could (hot)fix this, I would appreciate it a lot!

@TurkeyMcMac
Copy link
Contributor

Can you see what the param2 value is before the node is dug? (Using the F5 debug info.)

@debagos
Copy link
Author

debagos commented May 5, 2022

paramtype2 = "colorwallmounted"
param2 = 30
and the nodebox is wrong:
screencap
Please not that this node got colored with white dye.

@TurkeyMcMac
Copy link
Contributor

I can reproduce the crash. It makes sense, since 30 % 8 = 6. But I don't know how the node got that way.

To prevent the crash, this patch to Mesecons should work:

diff --git a/mesecons/presets.lua b/mesecons/presets.lua
index e10dd36..64f2bff 100644
--- a/mesecons/presets.lua
+++ b/mesecons/presets.lua
@@ -74,6 +74,7 @@ end
 
 mesecon.rules.wallmounted_get = function(node)
 	local dir = minetest.wallmounted_to_dir(node.param2)
+	if not dir then return {} end
 	return rules_from_dir(rules_wallmounted, dir)
 end

@debagos
Copy link
Author

debagos commented May 5, 2022

Thank you very much for your help @TurkeyMcMac, your information about the param2 stuff and the little hotfix! ❤️

@sfan5 sfan5 changed the title Attempt to index NiL value. Attempt to index nil value caused by nodes with invalid param2 Jun 24, 2022
@Niklp09
Copy link
Member

Niklp09 commented Aug 25, 2022

@TurkeyMcMac can you make a PR with your patch?

@TurkeyMcMac
Copy link
Contributor

Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants