From c3338d3881d413589d7e316eb867a3cb0eb2d7c0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 9 Apr 2025 15:11:04 +0900 Subject: [PATCH 1/2] Avoid resetting indexmaps causing exceptions --- .../VRM/Runtime/SpringBone/Logic/SpringBoneSystem.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Assets/VRM/Runtime/SpringBone/Logic/SpringBoneSystem.cs b/Assets/VRM/Runtime/SpringBone/Logic/SpringBoneSystem.cs index a44091bf1..4942a4c11 100644 --- a/Assets/VRM/Runtime/SpringBone/Logic/SpringBoneSystem.cs +++ b/Assets/VRM/Runtime/SpringBone/Logic/SpringBoneSystem.cs @@ -38,7 +38,15 @@ namespace VRM.SpringBone for (int i = 0; i < m_joints.Count; ++i) { - m_jointIndexMap.Add(m_joints[i].Item1, i); + // #2617 + // Keys may not be unique + m_jointIndexMap[m_joints[i].Item1] = i; + + // this index refer m_joints + // if not unique, + // m_joints[] = { (a, a_state), (b, b_state), (a, a_state) ... }; + // m_joints[0] and m_joints[2] is same. + // The above code is ok } } From 1dd9372617c795d7e82785dc7ae303e4d806b1cb Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 9 Apr 2025 23:57:16 +0900 Subject: [PATCH 2/2] add duplicate joint test --- Assets/VRM/Tests/VRMSpringBoneTests.cs | 31 +++++++++++++++++++++ Assets/VRM/Tests/VRMSpringBoneTests.cs.meta | 11 ++++++++ 2 files changed, 42 insertions(+) create mode 100644 Assets/VRM/Tests/VRMSpringBoneTests.cs create mode 100644 Assets/VRM/Tests/VRMSpringBoneTests.cs.meta diff --git a/Assets/VRM/Tests/VRMSpringBoneTests.cs b/Assets/VRM/Tests/VRMSpringBoneTests.cs new file mode 100644 index 000000000..c9182d616 --- /dev/null +++ b/Assets/VRM/Tests/VRMSpringBoneTests.cs @@ -0,0 +1,31 @@ +using System.IO; +using System.Linq; +using NUnit.Framework; +using UnityEngine; + +namespace VRM +{ + public class VRMSpringBoneTests + { + static string AliciaPath + { + get + { + return Path.GetFullPath(Application.dataPath + "/../Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm") + .Replace("\\", "/"); + } + } + + [Test] + public void DuplicatedJoints() + { + using var loaded = TestVrm0X.LoadPathAsBuiltInRP(AliciaPath); + var sb = loaded.GetComponentInChildren(); + + // make duplicate #2617 + sb.RootBones.Add(sb.RootBones[0].GetChild(0)); + + Assert.DoesNotThrow(() => sb.Setup()); + } + } +} \ No newline at end of file diff --git a/Assets/VRM/Tests/VRMSpringBoneTests.cs.meta b/Assets/VRM/Tests/VRMSpringBoneTests.cs.meta new file mode 100644 index 000000000..715be0a3b --- /dev/null +++ b/Assets/VRM/Tests/VRMSpringBoneTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e52c8edc85e2460489f05eebc7f1f201 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: