From a4abbf8824f893558861bff2893181ae02ed284d Mon Sep 17 00:00:00 2001
From: "Y. Wang" <yw05@forksworld.de>
Date: Sat, 13 Aug 2022 16:16:17 +0200
Subject: Add hotfix for path invalidation

---
 advtrains_interlocking/routesetting.lua            | 3 ++-
 advtrains_interlocking/signal_api.lua              | 6 ++++--
 advtrains_interlocking/signal_aspect_accessors.lua | 5 +++++
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua
index e792d28..9973569 100644
--- a/advtrains_interlocking/routesetting.lua
+++ b/advtrains_interlocking/routesetting.lua
@@ -341,7 +341,8 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel)
 			end
 		else
 			--atdebug("Committed Route:",tcbs.routeset)
-			has_changed_aspect = true
+			-- set_route now sets the signal aspects
+			--has_changed_aspect = true
 		end
 	end
 	if has_changed_aspect then
diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua
index 1c6ed27..e615692 100644
--- a/advtrains_interlocking/signal_api.lua
+++ b/advtrains_interlocking/signal_api.lua
@@ -227,8 +227,10 @@ function advtrains.interlocking.signal_on_aspect_changed(pos)
 	local ipts, iconn = advtrains.interlocking.db.get_ip_by_signalpos(pos)
 	if not ipts then return end
 	local ipos = minetest.string_to_pos(ipts)
-	
-	advtrains.invalidate_all_paths_ahead(ipos)
+
+	-- FIXME: invalidate_all_paths_ahead does not appear to always work as expected
+	--advtrains.invalidate_all_paths_ahead(ipos)
+	minetest.after(0, advtrains.invalidate_all_paths, ipos)
 end
 
 function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack, pointed_thing)
diff --git a/advtrains_interlocking/signal_aspect_accessors.lua b/advtrains_interlocking/signal_aspect_accessors.lua
index e23aa13..a1cbd4e 100644
--- a/advtrains_interlocking/signal_aspect_accessors.lua
+++ b/advtrains_interlocking/signal_aspect_accessors.lua
@@ -108,6 +108,11 @@ local function set_aspect(pos, asp, skipdst)
 		if (not skipdst) and aspect_changed then
 			D.update_main(pos)
 		end
+		--[[
+		local dbgmsg = string.format("[%s]set_aspect(%s,%s,%s)", os.clock(), minetest.pos_to_string(pos), minetest.serialize(asp), tostring(skipdst))
+		dbgmsg = debug.traceback(dbgmsg, 2)
+		minetest.chat_send_all(dbgmsg)
+		--]]
 	end
 end
 
-- 
cgit v1.2.3