Skip to content

Commit

Permalink
Merge pull request #1 from mojopon/mojopon/hotfix-1
Browse files Browse the repository at this point in the history
[springbone] SpringBone が無いモデルの NullReferenceException を修正
  • Loading branch information
mojopon authored Oct 18, 2024
2 parents 49dd34f + e8f221a commit cddd660
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ public class Vrm0XFastSpringboneRuntime : IVrm0XSpringBoneRuntime
SpringBoneJobs.FastSpringBoneService m_service;
FastSpringBoneBuffer m_buffer;

public Vrm0XFastSpringboneRuntime()
{
m_service = SpringBoneJobs.FastSpringBoneService.Instance;
}

public async Task InitializeAsync(GameObject vrm, IAwaitCaller awaitCaller)
{
m_vrm = vrm;
m_service = SpringBoneJobs.FastSpringBoneService.Instance;

// default update の停止
foreach (VRMSpringBone sb in vrm.GetComponentsInChildren<VRMSpringBone>())
Expand Down Expand Up @@ -69,9 +73,8 @@ async Task RegisterAsync(IAwaitCaller awaitCaller)

public void ReconstructSpringBone()
{
var disposer = m_vrm.gameObject.GetComponent<FastSpringBoneDisposer>();
Unregister();
var task = RegisterAsync(new ImmediateCaller());
var _ = RegisterAsync(new ImmediateCaller());
}

public void RestoreInitialTransform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class Vrm10FastSpringboneRuntime : IVrm10SpringBoneRuntime
private FastSpringBones.FastSpringBoneService m_fastSpringBoneService;
private FastSpringBoneBuffer m_fastSpringBoneBuffer;

public Vrm10FastSpringboneRuntime()
{
m_fastSpringBoneService = FastSpringBones.FastSpringBoneService.Instance;
}

public void SetJointLevel(Transform joint, BlittableJointMutable jointSettings)
{
if (m_fastSpringBoneService.BufferCombiner.Combined is FastSpringBoneCombinedBuffer combined)
Expand All @@ -37,7 +42,6 @@ public void SetModelLevel(Transform modelRoot, BlittableModelLevel modelSettings

public async Task InitializeAsync(Vrm10Instance instance, IAwaitCaller awaitCaller)
{
m_fastSpringBoneService = FastSpringBones.FastSpringBoneService.Instance;
m_instance = instance;

// NOTE: FastSpringBoneService は UnitTest などでは動作しない
Expand All @@ -49,8 +53,11 @@ public async Task InitializeAsync(Vrm10Instance instance, IAwaitCaller awaitCall

public void Dispose()
{
m_fastSpringBoneService.BufferCombiner.Unregister(m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer.Dispose();
if (m_fastSpringBoneBuffer != null)
{
m_fastSpringBoneService.BufferCombiner.Unregister(m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer.Dispose();
}
}

/// <summary>
Expand Down
15 changes: 8 additions & 7 deletions Assets/VRM10/Runtime/IO/Vrm10Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,15 @@ protected override async Task FinalizeAsync(IAwaitCaller awaitCaller)
if (UniGLTF.Extensions.VRMC_springBone.GltfDeserializer.TryGet(Data.GLTF.extensions, out UniGLTF.Extensions.VRMC_springBone.VRMC_springBone springBone))
{
await LoadSpringBoneAsync(awaitCaller, controller, springBone);
}

if (Application.isPlaying)
{
// EditorImport では呼ばない
// Vrm10Runtime で初期化していたが、 async にするためこちらに移動 v0.127
// RuntimeGltfInstance にアクセスしたいのだが OnLoadHierarchy ではまだ attach されてなかった v0.128
await m_springboneRuntime.InitializeAsync(controller, awaitCaller);
}
if (Application.isPlaying)
{
// EditorImport では呼ばない
// Vrm10Runtime で初期化していたが、 async にするためこちらに移動 v0.127
// RuntimeGltfInstance にアクセスしたいのだが OnLoadHierarchy ではまだ attach されてなかった v0.128
// VRMC_springBone が無くても初期化する v0.127.2
await m_springboneRuntime.InitializeAsync(controller, awaitCaller);
}

// constraint
Expand Down

0 comments on commit cddd660

Please sign in to comment.