Skip to content

Commit

Permalink
Merge pull request #2476 from ousttrue/fix/springboneruntime_default
Browse files Browse the repository at this point in the history
[1.0][SpringboneRuntime] SpringboneRuntime が null だと NullReference Exception
  • Loading branch information
ousttrue authored Oct 25, 2024
2 parents 91636a6 + 030052a commit e16c286
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
21 changes: 10 additions & 11 deletions Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,26 @@ internal Vrm10Runtime MakeRuntime(bool useControlRig)
{
if (m_springBoneRuntime == null)
{
// シーン配置モデルが play された
// springbone が無い => シーン配置モデルが play されたと見做す
var provider = GetComponent<IVrm10SpringBoneRuntimeProvider>();
if (provider != null)
{
// 明示的カスタマイズ
m_springBoneRuntime = provider.CreateSpringBoneRuntime();
}
else

if (m_springBoneRuntime == null)
{
// deafult に fallback
if (Application.isEditor)
{
m_springBoneRuntime = new Vrm10FastSpringboneRuntimeStandalone();
}
else
{
m_springBoneRuntime = new Vrm10FastSpringboneRuntime();
}
// シーン配置 play のデフォルトは singletone ではない方
m_springBoneRuntime = new Vrm10FastSpringboneRuntimeStandalone();
}

m_springBoneRuntime.InitializeAsync(this, new ImmediateCaller());
}
else
{
// importer 内で InitializeAsync が呼び出し済み
}
return new Vrm10Runtime(this, useControlRig, m_springBoneRuntime);
}

Expand Down
35 changes: 19 additions & 16 deletions Assets/VRM10/Runtime/IO/Vrm10Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,27 @@ public Vrm10Importer(
m_externalMap = new Dictionary<SubAssetKey, UnityEngine.Object>();
}

m_springboneRuntime = MakeDefaultRuntime(springboneRuntime, isAssetImport);
}

static IVrm10SpringBoneRuntime MakeDefaultRuntime(IVrm10SpringBoneRuntime runtime, bool isAssetImport)
{
if (runtime != null)
if (springboneRuntime == null)
{
return runtime;
}

if (isAssetImport)
{
// 何もしない dummy
return new Vrm10NopSpringboneRuntime();
if (isAssetImport)
{
// 何もしない dummy
springboneRuntime = new Vrm10NopSpringboneRuntime();
}
else
{
if (!Application.isPlaying)
{
// play中でない。test 対策
springboneRuntime = new Vrm10FastSpringboneRuntimeStandalone();
}
else
{
springboneRuntime = new Vrm10FastSpringboneRuntime();
}
}
}

// Vrm10Instance.MakeRuntime に移譲
return null;
m_springboneRuntime = springboneRuntime;
}

static void AssignHumanoid(List<VrmLib.Node> nodes, UniGLTF.Extensions.VRMC_vrm.HumanBone humanBone, VrmLib.HumanoidBones key)
Expand Down

0 comments on commit e16c286

Please sign in to comment.