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))