fix: crash when undoing setup outfit (#680)

Closes: #571
This commit is contained in:
bd_ 2024-02-18 21:56:59 +09:00 committed by GitHub
parent d57e211d0b
commit 42ca90a6bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 7 deletions

View File

@ -1,4 +1,6 @@
using System; #region
using System;
using System.Collections.Generic; using System.Collections.Generic;
using nadena.dev.modular_avatar.JacksonDunstan.NativeCollections; using nadena.dev.modular_avatar.JacksonDunstan.NativeCollections;
using Unity.Burst; using Unity.Burst;
@ -7,6 +9,8 @@ using Unity.Jobs;
using UnityEngine; using UnityEngine;
using UnityEngine.Jobs; using UnityEngine.Jobs;
#endregion
namespace nadena.dev.modular_avatar.core.armature_lock namespace nadena.dev.modular_avatar.core.armature_lock
{ {
internal class BidirectionalArmatureLock : IDisposable, IArmatureLock internal class BidirectionalArmatureLock : IDisposable, IArmatureLock
@ -131,8 +135,9 @@ namespace nadena.dev.modular_avatar.core.armature_lock
LastOp.Complete(); LastOp.Complete();
_baseBoneAccess.Dispose(); // work around crashes caused by destroying TransformAccessArray from within Undo processing
_mergeBoneAccess.Dispose(); DeferDestroy.DeferDestroyObj(_baseBoneAccess);
DeferDestroy.DeferDestroyObj(_mergeBoneAccess);
BaseBones.Dispose(); BaseBones.Dispose();
MergeBones.Dispose(); MergeBones.Dispose();
SavedMerge.Dispose(); SavedMerge.Dispose();

View File

@ -0,0 +1,18 @@
#region
using System;
#endregion
namespace nadena.dev.modular_avatar.core.armature_lock
{
internal static class DeferDestroy
{
internal static void DeferDestroyObj(IDisposable obj)
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.delayCall += () => obj.Dispose();
#endif
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 587f90fe407f4a8287c927c435d84880
timeCreated: 1708260240

View File

@ -1,4 +1,6 @@
using System; #region
using System;
using System.Collections.Generic; using System.Collections.Generic;
using nadena.dev.modular_avatar.JacksonDunstan.NativeCollections; using nadena.dev.modular_avatar.JacksonDunstan.NativeCollections;
using Unity.Burst; using Unity.Burst;
@ -10,6 +12,8 @@ using UnityEngine.Jobs;
using UnityEditor; using UnityEditor;
#endif #endif
#endregion
namespace nadena.dev.modular_avatar.core.armature_lock namespace nadena.dev.modular_avatar.core.armature_lock
{ {
internal class OnewayArmatureLock : IDisposable, IArmatureLock internal class OnewayArmatureLock : IDisposable, IArmatureLock
@ -203,6 +207,8 @@ namespace nadena.dev.modular_avatar.core.armature_lock
LastOp.Complete(); LastOp.Complete();
_baseBonesAccessor.SetTransforms(_baseBones);
_mergeBonesAccessor.SetTransforms(_mergeBones);
_fault.Value = 0; _fault.Value = 0;
_wroteAny.Value = 0; _wroteAny.Value = 0;
@ -293,7 +299,7 @@ namespace nadena.dev.modular_avatar.core.armature_lock
public void Dispose() public void Dispose()
{ {
if (_disposed) return; if (_disposed) return;
LastOp.Complete(); LastOp.Complete();
_boneStaticData.Dispose(); _boneStaticData.Dispose();
_mergeSavedState.Dispose(); _mergeSavedState.Dispose();
@ -301,8 +307,9 @@ namespace nadena.dev.modular_avatar.core.armature_lock
_mergeState.Dispose(); _mergeState.Dispose();
_fault.Dispose(); _fault.Dispose();
_wroteAny.Dispose(); _wroteAny.Dispose();
_baseBonesAccessor.Dispose(); // work around crashes caused by destroying TransformAccessArray from within Undo processing
_mergeBonesAccessor.Dispose(); DeferDestroy.DeferDestroyObj(_baseBonesAccessor);
DeferDestroy.DeferDestroyObj(_mergeBonesAccessor);
_disposed = true; _disposed = true;
#if UNITY_EDITOR #if UNITY_EDITOR