Any idea on how to fix bad argument #2 to 'find_node_near'

minetestcr
Member
 
Posts: 57
Joined: Fri Feb 13, 2015 21:31

Any idea on how to fix bad argument #2 to 'find_node_near'

by minetestcr » Tue Oct 04, 2016 00:33

Hello. I opened minetest today, after about a month of no activity, opened my world, and when I got near certain region, it crashed....
I have minetest 0.4.14-dev
Ubuntu 14.04
this is the debug:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
2016-10-03 18:26:21: ACTION[Server]: singleplayer [127.0.0.1] joins game.
2016-10-03 18:26:21: ACTION[Server]: singleplayer joins game. List of players: singleplayer
2016-10-03 18:26:22: WARNING[Server]: Undeclared global variable "creative_inventory" accessed at ...jdigital/.minetest/mods/WorldEdit/worldedit_gui/init.lua:143
2016-10-03 18:26:29: WARNING[Server]: Undeclared global variable "spawn_plants" accessed at .../stjdigital/.minetest/mods/plantlife/plants_lib/init.lua:305
2016-10-03 18:26:37: ACTION[Server]: singleplayer sets time to 5555
2016-10-03 18:26:47: ERROR[Main]: ServerError: Lua: Runtime error from mod 'default' in callback LuaABM::trigger(): .../minetest/games/minetest_game/mods/default/functions.lua:320: bad argument #2 to 'find_node_near' (number expected, got nil)
2016-10-03 18:26:47: ERROR[Main]: stack traceback:
2016-10-03 18:26:47: ERROR[Main]:    [C]: in function 'find_node_near'
2016-10-03 18:26:47: ERROR[Main]:    .../minetest/games/minetest_game/mods/default/functions.lua:320: in function <.../minetest/games/minetest_game/mods/default/functions.lua:311>


thanks
 

User avatar
duane
Member
 
Posts: 776
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r

Re: Any idea on how to fix bad argument #2 to 'find_node_nea

by duane » Tue Oct 04, 2016 01:12

The code in question is:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
      local rad = minetest.registered_nodes[node.name].groups.leafdecay
      -- Assume ignore is a trunk, to make this
      -- work at the border of a loaded area
      if minetest.find_node_near(pos, rad, {"ignore", "group:tree"}) then
         return
      end


It's part of the general leaf decay function. It should probably read more like this, to avoid assuming its arguments are going to be there:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
      local rad = minetest.registered_nodes[node.name].groups.leafdecay

      if not (pos and rad) then
         return
      end

      -- Assume ignore is a trunk, to make this
      -- work at the border of a loaded area
      if minetest.find_node_near(pos, rad, {"ignore", "group:tree"}) then
         return
      end


Make that change to minetest_game/mods/default/functions.lua, and you shouldn't get any more crashes. However, there's still a node somewhere that doesn't have leafdecay set correctly. Finding that is probably more trouble than it's worth. If you see any odd leaves in your game, just remove them.
 

minetestcr
Member
 
Posts: 57
Joined: Fri Feb 13, 2015 21:31

Re: Any idea on how to fix bad argument #2 to 'find_node_nea

by minetestcr » Tue Oct 04, 2016 13:29

Thank you duane. My game doesn't have "minetest_game/mods/default/functions.lua", or at least, the "functions.lua" files that i found don't have the code you mention. Anyway, since you pointed me towards leafdecay, I deactivated moretrees mod and the game does not crash any more. Thanks.



duane wrote:The code in question is:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
      local rad = minetest.registered_nodes[node.name].groups.leafdecay
      -- Assume ignore is a trunk, to make this
      -- work at the border of a loaded area
      if minetest.find_node_near(pos, rad, {"ignore", "group:tree"}) then
         return
      end

 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 3 guests

cron