Do not crash if minetest.find_nodes_in_area() lies

This commit is contained in:
Nils Dagsson Moskopp 2021-12-15 12:55:33 +01:00 committed by cora
parent 4f33f626f5
commit 0b5fa14041
1 changed files with 16 additions and 8 deletions

View File

@ -75,14 +75,22 @@ local test_minetest_find_nodes_in_area_can_count = function(dtime)
local nodes_expected = math.pow( 1 + (2 * radius), 3 )
local nodes_counted = nnum[nodename]
local nodes_difference = nodes_expected - nodes_counted
-- Yes, the following line is supposed to crash the game in
-- the case that Minetest forgot how to count the number of
-- nodes in a three dimensional volume it just filled. This
-- function contains an excellent explanation on what not to
-- do further up. I strongly suggest to pester Minetest core
-- devs about this issue and not the author of the function,
-- should this test ever fail.
assert ( 0 == nodes_difference )
-- Originally, there was an assertion here that made the game
-- crash at startup if Minetest forgot how to count. This was
-- originally intended to avoid buggy engine releases, but it
-- mostly made people upset and hindered debugging. Also, the
-- assertion contained no error message hinting at the reason
-- for the crash, making it exceptionally user-unfriendly. It
-- follows that a game or mod should only assert on behaviour
-- of the Lua code, not the underlying implementation, unless
-- engine bugs are bad enough to permanently corrupt a world.
if ( 0 ~= nodes_difference ) then
minetest.debug(
"minetest.find_nodes_in_area() failed to find " ..
nodes_difference .. " nodes that were placed. " ..
"Downgrading to Minetest 5.4.1 might fix this."
)
end
end
minetest.after( 0, test_minetest_find_nodes_in_area_can_count )