From a3f1bebf12dcf302713fe80a3ac975821227b3d9 Mon Sep 17 00:00:00 2001 From: siimav Date: Mon, 18 Mar 2024 19:11:30 +0200 Subject: [PATCH] Do not add duplicate joints to KJRMultiJointManager dictionary --- .../KerbalJointReinforcement/KJRMultiJointManager.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/KerbalJointReinforcement/KerbalJointReinforcement/KJRMultiJointManager.cs b/KerbalJointReinforcement/KerbalJointReinforcement/KJRMultiJointManager.cs index 32bf248..eeaa254 100644 --- a/KerbalJointReinforcement/KerbalJointReinforcement/KJRMultiJointManager.cs +++ b/KerbalJointReinforcement/KerbalJointReinforcement/KJRMultiJointManager.cs @@ -155,11 +155,18 @@ public void RegisterMultiJoint(Part testPart, ConfigurableJoint multiJoint) List configJointList; if (multiJointDict.TryGetValue(testPart, out configJointList)) { + bool alreadyExists = false; for (int i = configJointList.Count - 1; i >= 0; --i) - if (configJointList[i] == null) + { + ConfigurableJoint joint = configJointList[i]; + if (joint == null) configJointList.RemoveAt(i); - configJointList.Add(multiJoint); + alreadyExists |= joint == multiJoint; + } + + if (!alreadyExists) + configJointList.Add(multiJoint); } else {