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

Crash if calling minetest.pointed_thing_to_face_pos and pointed_thing.above and pointed_thing.below are equal #6643

Closed
Wuzzy2 opened this issue Nov 18, 2017 · 12 comments
Labels
Bug Issues that were confirmed to be a bug @ Builtin

Comments

@Wuzzy2
Copy link
Contributor

Wuzzy2 commented Nov 18, 2017

Tested in MT 0.4.16.

Just call minetest.pointed_thing_to_face_pos with a pointed_thing of type="node", and above and below having equal positions.

There will be crash with this error:

ERROR: /usr/share/minetest/builtin/common/misc_helpers.lua:717: Attempt to perform arithmetic on a nil value

Example:
minetest.pointed_thing_to_face_pos(player, {type="node", above={x=0,y=0,z=0}, below={x=0,y=0,z=0})

How can above and below have the same positions, you ask? Easy: Just place a node when your head is inside a non-walkable and buildable_to node (e.g. jungle grass). Then you will get a pointed_thing in which both above and below have equal positions. At least in the on_place function of the item you place.

In Minetest Game 0.4.16, you can reproduce this if you stand inside jungle grass, fly and noclip a bit down (so you are inside the same node), then place a slab inside that jungle grass.

@Wuzzy2 Wuzzy2 changed the title minetest.pointed_thing_to_face_pos causes crash if above and below of pointed_thing are equal Crash if calling minetest.pointed_thing_to_face_pos if pointed_thing.above and pointed_thing.below are equal Nov 18, 2017
@Wuzzy2 Wuzzy2 changed the title Crash if calling minetest.pointed_thing_to_face_pos if pointed_thing.above and pointed_thing.below are equal Crash if calling minetest.pointed_thing_to_face_pos and pointed_thing.above and pointed_thing.below are equal Nov 18, 2017
@sfan5 sfan5 added the Bug Issues that were confirmed to be a bug label Nov 18, 2017
@paramat
Copy link
Contributor

paramat commented Dec 15, 2017

Was reported again (see below), should be an easy fix, if they're the same return a certain fixed position on the face.

2017-12-14 20:20:59: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'stairs' in callback item_OnPlace(): /usr/local/share/minetest/builtin/common/misc_helpers.lua:717: attempt to perform arithmetic on a nil value
2017-12-14 20:20:59: ERROR[Main]: Stack Traceback
2017-12-14 20:20:59: ERROR[Main]: ===============
2017-12-14 20:20:59: ERROR[Main]: (2) Lua field 'pointed_thing_to_face_pos' at file '/usr/local/share/minetest/builtin/common/misc_helpers.lua:717'
2017-12-14 20:20:59: ERROR[Main]: 	Local variables:
2017-12-14 20:20:59: ERROR[Main]: 	 placer = userdata: 0x00ee3698
2017-12-14 20:20:59: ERROR[Main]: 	 pointed_thing = table: 0x01a65678  {type:node, above:table: 0x01a65768, under:table: 0x01a656a0}
2017-12-14 20:20:59: ERROR[Main]: 	 eye_offset_first = table: 0x01a65980  {y:0, x:0, z:0}
2017-12-14 20:20:59: ERROR[Main]: 	 node_pos = table: 0x01a656a0  {y:26, x:-9948, z:7638}
2017-12-14 20:20:59: ERROR[Main]: 	 camera_pos = table: 0x01a65aa0  {y:24.121999740601, x:-9948.0546875, z:7638.46875}
2017-12-14 20:20:59: ERROR[Main]: 	 pos_off = table: 0x01a65bc0  {y:0, x:0, z:0}
2017-12-14 20:20:59: ERROR[Main]: 	 look_dir = table: 0x01a65c50  {y:0.47101190686226, x:-0.50647139549255, z:-0.72224271297455}
2017-12-14 20:20:59: ERROR[Main]: 	 offset = nil
2017-12-14 20:20:59: ERROR[Main]: 	 nc = nil
2017-12-14 20:20:59: ERROR[Main]: 	 oc = table: 0x01a65ce0  {1:y, 2:x, 3:z}
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = table: 0x01a65d08  {}
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = nil
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = number: nan
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = string: "z"
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = number: 0
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = number: 3
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = number: nan
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = string: "jump"
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = boolean: false
2017-12-14 20:20:59: ERROR[Main]: 	 (*temporary) = string: "attempt to perform arithmetic on a nil value"
2017-12-14 20:20:59: ERROR[Main]: (3) Lua function 'rotate' at file '/home/UGX/.minetest/games/UGXrealms/mods/minetest_game/stairs/init.lua:30' (best guess)
2017-12-14 20:20:59: ERROR[Main]: 	Local variables:
2017-12-14 20:20:59: ERROR[Main]: 	 itemstack = userdata: 0x01a65668
2017-12-14 20:20:59: ERROR[Main]: 	 placer = userdata: 0x00ee3698
2017-12-14 20:20:59: ERROR[Main]: 	 pointed_thing = table: 0x01a65678  {type:node, above:table: 0x01a65768, under:table: 0x01a656a0}
2017-12-14 20:20:59: ERROR[Main]: 	 p0 = table: 0x01a656a0  {y:26, x:-9948, z:7638}
2017-12-14 20:20:59: ERROR[Main]: 	 p1 = table: 0x01a65768  {y:26, x:-9948, z:7638}
2017-12-14 20:20:59: ERROR[Main]: 	 param2 = number: 2
2017-12-14 20:20:59: ERROR[Main]: 	 placer_pos = table: 0x01a65860  {y:24.121999740601, x:-9948.0546875, z:7638.46875}

@SmallJoker
Copy link
Member

@MarkuBu
As you wrote this function - could you please check whether the next face position in the direction of view can be returned here?

@MarkuBu
Copy link
Contributor

MarkuBu commented Dec 15, 2017

If you stand inside jungle grass you can't place nodes at all because you are inside the hitbox and you point to this hitbox and not to the node the crosshair points to.

All you can do is check above and below if they are equal.

Off topic: I think anyway that the hitbox of jungle grass is too big. Every time you walk through a jungle and try to punch or dig something you often hit jungle grass first. Will open an issue soon

@MarkuBu
Copy link
Contributor

MarkuBu commented Dec 15, 2017

Just place a node when your head is inside a non-walkable and buildable_to node (e.g. jungle grass)

To be honest I can't confirm this bug. I placed jungle grass, step inside and try to place a slab somewhere. Nothing happened.

@SmallJoker
Copy link
Member

You can reproduce it by standing inside a full node with a dry shrub or jungle grass above. That's also what Wuzzy described in the first post.
inside shrub

@MarkuBu
Copy link
Contributor

MarkuBu commented Dec 15, 2017

How can I stand in a full node in a regular game? As long as "noclip" is disabled or you "glitch" into a node somehow

However, best would be to add a check if above and below are equal. I won't try to find a solution to make such a rare and uncommon situation work.

@SmallJoker
Copy link
Member

I won't try to find a solution to make such a rare and uncommon situation work.

# If enabled, you can place blocks at the position (feet + eye level) where you stand.
# This is helpful when working with nodeboxes in small areas.
# type: bool
# enable_build_where_you_stand = false

Players can crash servers by turning this setting off and placing the nodes to get this condition. Is that important enough to fix it?

@MarkuBu
Copy link
Contributor

MarkuBu commented Dec 15, 2017

I already posted a solution. Check if above and below are equal. If yes, return and do nothing.

I'm not at home and can try it myself

And I didn't develop this function. The original function was from HybridDog, if I'm not wrong. I just adopted it to make it work for this situation

@MarkuBu
Copy link
Contributor

MarkuBu commented Dec 15, 2017

Two suggestions to solve this issue:

function core.pointed_thing_to_face_pos(placer, pointed_thing)
	if vector.equals(pointed_thing.above, pointed_thing.under) then
		return vector.new()
	end

If you return vector.new() a slab or stair will be placed on top of the node the player currently stands in. The jungle grass or whatever node is on top will be replaced

instead of return a new vector yo can return nil. But than you need to catch the nil in init.lua from the stairs mod

		local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing)
		if not finepos then
			return nil
		end
		local fpos = finepos.y % 1

In this case only the place sound is played, but nothing else happened.

@paramat paramat self-assigned this Dec 15, 2017
@paramat paramat removed their assignment May 15, 2018
@paramat
Copy link
Contributor

paramat commented May 15, 2018

Still crashing, will fix.

@paramat
Copy link
Contributor

paramat commented May 15, 2018

PR #7342
Best to return a vector similar to what would normally be returned, so returned 'under'.

@paramat
Copy link
Contributor

paramat commented May 16, 2018

#7342 merged.

@paramat paramat closed this as completed May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues that were confirmed to be a bug @ Builtin
Projects
None yet
Development

No branches or pull requests

5 participants