From fd4fa83a81191b5aea09ae8d369073da2bb04752 Mon Sep 17 00:00:00 2001 From: Ed Burke Date: Fri, 12 Dec 2025 01:56:54 -0500 Subject: [PATCH] script_comp: fix undesired resman container set mutations This commit modifies the method in which nwn_script_comp searches ResMan to deliver the desired ResRef. Previous behavior allowed for the ResMan.containers set to be mutatated in `nwn_script_comp::serviceRmDemand` when the deferred code was run as the scope expired. This caused the containers within the containers set to reorder, seemingly at random, losing the load order as specified by the user, potentially causing script compilation issues, specifically with user-defined files that shadow big-sourced files. --- nwn_script_comp.nim | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/nwn_script_comp.nim b/nwn_script_comp.nim index 6246b3c..c3aa8e8 100644 --- a/nwn_script_comp.nim +++ b/nwn_script_comp.nim @@ -150,16 +150,14 @@ proc serviceRmDemand(rm: ResMan, resref: ResRef, searchPath: seq[RMSearchPathEnt of pcFile: resContainerCache[q[1]] = newResFile(q[1]) else: continue containers.add resContainerCache[q[1]] + + containers &= rm.containers + for c in containers: - rm.add(c) - defer: - for c in containers: - rm.del(c) + if c.contains(resref): + return c.demand(resref).readAll - if not rm.contains(resref): - return "" - else: - return rm.demand(resref).readAll + return "" var chDemandResRef: Channel[tuple[ resref: ResRef,