Giter Site home page Giter Site logo

Stack overflow with detector about techpack HOT 5 CLOSED

joe7575 avatar joe7575 commented on September 2, 2024
Stack overflow with detector

from techpack.

Comments (5)

fluxionary avatar fluxionary commented on September 2, 2024

Actually, nevermind that fix. That fixed my local "replication" of the issue, but the issue on the server seems to involve multiple detectors in a sequence or something, so they're still creating an infinite loop and crashing.

from techpack.

fluxionary avatar fluxionary commented on September 2, 2024

And actually, you can create this issue just by creating a long enough linear sequence of detectors (though you need quite a few). No loop required.

from techpack.

joe7575 avatar joe7575 commented on September 2, 2024

What about that proposal?

diff --git a/tubelib_addons1/detector.lua b/tubelib_addons1/detector.lua
index f7c5ad9..7bfd552 100644
--- a/tubelib_addons1/detector.lua
+++ b/tubelib_addons1/detector.lua
@@ -19,14 +19,17 @@ local function switch_on(pos)
 		node.name = "tubelib_addons1:detector_active"
 		minetest.swap_node(pos, node)
 		minetest.get_node_timer(pos):start(1)
-		local meta = minetest.get_meta(pos)
-		local own_num = meta:get_string("own_num")
-		local numbers = meta:get_string("numbers")
-		local placer_name = meta:get_string("placer_name")
-		tubelib.send_message(numbers, placer_name, nil, "on", own_num)
 	end
 end
 
+local function send_on_msg(pos)
+	local meta = minetest.get_meta(pos)
+	local own_num = meta:get_string("own_num")
+	local numbers = meta:get_string("numbers")
+	local placer_name = meta:get_string("placer_name")
+	tubelib.send_message(numbers, placer_name, nil, "on", own_num)
+end
+
 local function switch_off(pos)
 	if tubelib.data_not_corrupted(pos) then
 		local node = minetest.get_node(pos)
@@ -128,12 +131,12 @@ minetest.register_craft({
 	},
 })
 
-
-tubelib.register_node("tubelib_addons1:detector", {"tubelib_addons1:detector_active"}, {
+tubelib.register_node("tubelib_addons1:detector", {}, {
 	on_push_item = function(pos, side, item)
 		local player_name = minetest.get_meta(pos):get_string("player_name")
+		switch_on(pos)
 		if tubelib.push_items(pos, "R", item, player_name) then
-			switch_on(pos)
+			send_on_msg(pos)
 			return true
 		end
 		return false

It will not solve the "endless line of detectors", but is this a real server scenario?

from techpack.

fluxionary avatar fluxionary commented on September 2, 2024

If I'm reading that right, as soon as something possibly comes in, it switches the machine to the "on" node, and so, because you removed the active node from the declaration, no longer can process input. Then it does the check of where to sends stuff, and if that succeeds, it triggers the send message logic.

That sounds like it should work, but here's my 2nd solution on BlS, which simply refuses all input on the detector except from the appropriate side. I reverted the "self loop" check I had earlier. This prevented the issue in all configurations I could cook up.

I did a quick check and am (nearly) certain there aren't any other machines that accept items and immediately send them out again, so this is probably the only change needed to prevent stack overflows (unless something really insane happens). At this point, I feel the issue of someone putting several thousand detectors in series isn't really a sensible concern, so I'm happy with my solution.

The "broken" machines on BlS turned out to be two detectors that were both aimed at each others output, due to a couple of misconfigured teleporters.

from techpack.

joe7575 avatar joe7575 commented on September 2, 2024

You are right, your proposal is much better. I will take it over. Thanks

from techpack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.