From aefc390cc93bc230d6605244cfdb186763c94ab2 Mon Sep 17 00:00:00 2001 From: Duane Date: Sat, 30 Jul 2016 21:03:58 -0500 Subject: [PATCH] Force garbage collection. --- mapgen.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mapgen.lua b/mapgen.lua index 609d804..8435b33 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -468,14 +468,6 @@ local function generate(p_minp, p_maxp, seed) vm:update_liquids() vm:write_to_map() end - - -- Deal with memory issues. This, of course, is supposed to be automatic. - minetest.after(0, function() - if math.floor(collectgarbage("count")/1024) > 400 then - print("Fun Caves: Manually collecting garbage...") - collectgarbage("collect") - end - end) end @@ -493,6 +485,16 @@ end local function pgenerate(...) + if math.floor(collectgarbage("count")/1024) > 400 then + print("Fun Caves: Manually collecting garbage...") + collectgarbage("collect") + + -- Slow down to allow time to free memory. + local clock = os.clock + local t0 = clock() + while clock() - t0 <= 2 do end + end + local status, err = pcall(generate, ...) if not status then print(dump(err))