try to circumvent Out Of Memory error (Win64)

See https://gitlab.com/4w/mtimer/issues/7
This commit is contained in:
Dirk Sohler 2019-03-11 22:11:25 +01:00
parent c74dcf708a
commit abc8fd5b55
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
4 changed files with 27 additions and 0 deletions

@ -16,6 +16,9 @@ local S = minetest.get_translator('mtimer')
mtimer = {
translator = S,
dialog = {},
config = {
manual_gc = minetest.settings:get_bool('mtimer_manual_gc', false)
},
meta = {
visible = { key = 'mtimer:visible', default = 'true' },
position = { key = 'mtimer:position', default = 'bl' },

10
settingtypes.txt Normal file

@ -0,0 +1,10 @@
# Manual Lua garbage collection
#
# This setting addresses a bug that reportedly happens
# on Windows. Lua seems to run out of memory. When this
# setting is enabled mTimer runs the Lua garbage
# collector automatically every 10 seconds.
#
# If youre on Windows and your game does not crash
# simply ignore this setting.
mtimer_manual_gc (Perform manual Lua garbage collection) bool false

@ -1,5 +1,6 @@
local m = mtimer
local update_timer = m.update_timer
local manual_gc = m.config.manual_gc
local connected_players = minetest.get_connected_players
local timer = 0
@ -17,3 +18,15 @@ minetest.register_globalstep(function(dtime)
timer = 0
end)
-- @see https://gitlab.com/4w/mtimer/issues/7
if manual_gc == true then
local gc_timer = 0
minetest.register_globalstep(function(dtime)
gc_timer = gc_timer + dtime;
if gc_timer < 10 then return end
collectgarbage()
gc_timer = 0
end)
end

@ -1,5 +1,6 @@
local m = mtimer
-- Calculate HUD positions and offsets
--
-- Based on the given named position a table of positional tables is returned