OgelGames / beacon

A redo of the Minetest beacon mod by AgentNagel42 (WIP)
Other
4 stars 3 forks source link

Crash with beams rotated to unexpected param2 #26

Closed SwissalpS closed 3 months ago

SwissalpS commented 3 months ago

Using replacer set to rotation only mode, set it to e.g. prefab coloured grey, or any other colour greater than param2 of 23, use replacer on beacon beam. ---> server crashes because in this line a nil value is passed to vector.add https://github.com/OgelGames/beacon/blob/2fdcd971a53dc830609d45560a41ebbd4117fd66/register.lua#L31

dirty workaround:

local under_pos = vector.add(pos, beacon.param2_to_under[node.param2] or beacon.param2_to_under[0])

or only work on beams that have param2 < 24

Cleaner is to do some modular operation on param2 to ensure it's under 24.

local under_pos = vector.add(pos, beacon.param2_to_under[node.param2 % 24])

This may need to be done at other places too.

OgelGames commented 3 months ago

The correct solution is a double modulo operation, because that's what the engine does when drawing the node: https://github.com/minetest/minetest/blob/85878d894ae944e9044c7f29b5285d96b19f5a1f/src/mapnode.cpp#L62 https://github.com/OgelGames/beacon/blob/1a6b6bc71bd25abf4e49cdbba3edbec92ed2a71f/register.lua#L51

SwissalpS commented 3 months ago

Yes, I had a hunch it wasn't as simple as I had sketched. Thanks. Looks like you also addressed the isue with slowly degrading directions :D