]> git.lizzy.rs Git - Crafter.git/commitdiff
Stop stack overflows
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sat, 27 Jun 2020 13:29:19 +0000 (09:29 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sat, 27 Jun 2020 13:29:19 +0000 (09:29 -0400)
mods/redstone/init.lua
mods/redstone/inverter.lua

index 5287f9eba4ad6a98159bc53236695e55545c2b45..a6307683dd0a7fb56a9ec3e54a4a800e02044b2f 100644 (file)
@@ -244,7 +244,6 @@ local boundary
 local function calculate(pos)
 
        boundary = create_boundary_box(pos)
-
        --pathfind through memory map   
        for x,index_x in pairs(boundary) do
                for y,index_y in pairs(index_x) do
@@ -300,13 +299,27 @@ function redstone.inject(pos,data)
 end
 
 
+local recursion_check = {}
 function redstone.update(pos)
-       calculate(pos)
-end
-
+       local s_pos = minetest.serialize(pos)
+       if not recursion_check[s_pos] then
+               recursion_check[s_pos] = 0
+       end
+       recursion_check[s_pos] = recursion_check[s_pos] + 1
 
+       if recursion_check[s_pos] > 50 then
+               minetest.after(0,function()
+                       minetest.dig_node(pos)
+               end)
+               return
+       end
 
+       calculate(pos)
+end
 
+minetest.register_globalstep(function()
+       recursion_check = {}
+end)
 
 
 ----------------------------------------------------------------------------
index dbf55edba853f78254b661d98b1d9267aa93eefc..870f662297676cff349eae4de7e59563572c4c06 100644 (file)
@@ -51,10 +51,7 @@ redstone.register_activator({
                        dir = dir
                })
 
-               minetest.after(0,function()
-                       redstone.update(vector.add(pos,dir))
-                       redstone.update(vector.subtract(pos,dir))
-               end)
+               redstone.update(pos)
        end
 })
 
@@ -126,10 +123,7 @@ redstone.register_activator({
                        input  = vector.multiply(dir,-1),
                        dir = dir
                })
-               minetest.after(0,function()
-                       redstone.update(vector.add(pos,dir))
-                       redstone.update(vector.subtract(pos,dir))
-               end)
+               redstone.update(pos)
        end
 })