From 0b5fa14041bd3a115e952d28821813b3af82b673 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Wed, 15 Dec 2021 12:55:33 +0100 Subject: [PATCH] Do not crash if minetest.find_nodes_in_area() lies --- mods/MISC/mcl_selftests/init.lua | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/mods/MISC/mcl_selftests/init.lua b/mods/MISC/mcl_selftests/init.lua index 9e0adae0..0a68d9b3 100644 --- a/mods/MISC/mcl_selftests/init.lua +++ b/mods/MISC/mcl_selftests/init.lua @@ -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 )