diff --git a/PropUndoButton/Main.cs b/PropUndoButton/Main.cs index 9498515..c831b1a 100644 --- a/PropUndoButton/Main.cs +++ b/PropUndoButton/Main.cs @@ -159,14 +159,7 @@ public class PropUndoButton : MelonMod for (int i = propsList.Count - 1; i >= 0; i--) { CVRSyncHelper.PropData propData = propsList[i]; - - if (propData.Spawnable == null) - { - propData.Recycle(); - continue; - } - - propData.Spawnable.Delete(); + SafeDeleteProp(propData); } return false; @@ -181,13 +174,7 @@ public class PropUndoButton : MelonMod return; } - if (propData.Spawnable == null) - { - propData.Recycle(); - return; - } - - propData.Spawnable.Delete(); + SafeDeleteProp(propData); } public static void RedoProp() @@ -248,6 +235,31 @@ public class PropUndoButton : MelonMod } } + private static void SafeDeleteProp(CVRSyncHelper.PropData propData) + { + //fixes getting props stuck in limbo state if spawn & delete fast + if (propData.Spawnable == null && propData.Wrapper != null) + { + UnityEngine.Object.DestroyImmediate(propData.Wrapper); + propData.Recycle(); + } + else if (propData.Spawnable != null) + { + propData.Spawnable.Delete(); + } + + //if an undo attempt is made right after spawning a prop, the + //spawnable & wrapper will both be null, so the delete request + //will be ignored- same with Delete All button in Menu now + + //so the bug causing props to get stuck is due to the propData + //being wiped before the prop spawnable & wrapper were created + + //i am unsure if i should attempt an undo of second in line prop, + //just in case some issue happens and causes the mod to lock up here. + //It should be fine though, as reloading world should clear propData...? + } + private static bool IsPropSpawnAllowed() { return MetaPort.Instance.worldAllowProps diff --git a/PropUndoButton/SFX/sfx_redo.wav b/PropUndoButton/SFX/sfx_redo.wav index 9bc7f67..41bb0cf 100644 Binary files a/PropUndoButton/SFX/sfx_redo.wav and b/PropUndoButton/SFX/sfx_redo.wav differ diff --git a/PropUndoButton/SFX/sfx_spawn.wav b/PropUndoButton/SFX/sfx_spawn.wav index 3ddb522..ab2aef3 100644 Binary files a/PropUndoButton/SFX/sfx_spawn.wav and b/PropUndoButton/SFX/sfx_spawn.wav differ diff --git a/PropUndoButton/SFX/sfx_undo.wav b/PropUndoButton/SFX/sfx_undo.wav index bd47619..84f0cf7 100644 Binary files a/PropUndoButton/SFX/sfx_undo.wav and b/PropUndoButton/SFX/sfx_undo.wav differ diff --git a/PropUndoButton/SFX/sfx_warn.wav b/PropUndoButton/SFX/sfx_warn.wav index 676c6b9..8e96b57 100644 Binary files a/PropUndoButton/SFX/sfx_warn.wav and b/PropUndoButton/SFX/sfx_warn.wav differ