Avoid recursive reprocessing of avatars

This commit is contained in:
bd_ 2022-12-18 13:19:09 +09:00
parent 1a12a4b6bd
commit ab2761a30f

View File

@ -40,6 +40,12 @@ namespace nadena.dev.modular_avatar.core.editor
// Place after EditorOnly processing (which runs at -1024) but hopefully before most other user callbacks // Place after EditorOnly processing (which runs at -1024) but hopefully before most other user callbacks
public int callbackOrder => -25; public int callbackOrder => -25;
/// <summary>
/// Avoid recursive activation of avatar processing by suppressing starting processing while processing is
/// already in progress.
/// </summary>
private static bool nowProcessing = false;
public delegate void AvatarProcessorCallback(GameObject obj); public delegate void AvatarProcessorCallback(GameObject obj);
/// <summary> /// <summary>
@ -117,11 +123,15 @@ namespace nadena.dev.modular_avatar.core.editor
public static void ProcessAvatar(GameObject avatarGameObject) public static void ProcessAvatar(GameObject avatarGameObject)
{ {
BoneDatabase.ResetBones(); if (nowProcessing) return;
PathMappings.Clear();
try try
{ {
nowProcessing = true;
BoneDatabase.ResetBones();
PathMappings.Clear();
// Sometimes people like to nest one avatar in another, when transplanting clothing. To avoid issues // Sometimes people like to nest one avatar in another, when transplanting clothing. To avoid issues
// with inconsistently determining the avatar root, we'll go ahead and remove the extra sub-avatars // with inconsistently determining the avatar root, we'll go ahead and remove the extra sub-avatars
// here. // here.
@ -149,9 +159,13 @@ namespace nadena.dev.modular_avatar.core.editor
PhysboneBlockerPass.Process(avatarGameObject); PhysboneBlockerPass.Process(avatarGameObject);
AfterProcessing?.Invoke(avatarGameObject); AfterProcessing?.Invoke(avatarGameObject);
FixupAnimatorDebugData(avatarGameObject);
} }
finally finally
{ {
nowProcessing = false;
// Ensure that we clean up AvatarTagComponents after failed processing. This ensures we don't re-enter // Ensure that we clean up AvatarTagComponents after failed processing. This ensures we don't re-enter
// processing from the Awake method on the unprocessed AvatarTagComponents // processing from the Awake method on the unprocessed AvatarTagComponents
foreach (var component in avatarGameObject.GetComponentsInChildren<AvatarTagComponent>(true)) foreach (var component in avatarGameObject.GetComponentsInChildren<AvatarTagComponent>(true))
@ -159,8 +173,6 @@ namespace nadena.dev.modular_avatar.core.editor
UnityEngine.Object.DestroyImmediate(component); UnityEngine.Object.DestroyImmediate(component);
} }
} }
FixupAnimatorDebugData(avatarGameObject);
} }
[SuppressMessage("ReSharper", "PossibleNullReferenceException")] [SuppressMessage("ReSharper", "PossibleNullReferenceException")]