Search Issue Tracker

By Design

Votes

1

Found in

2021.3.24f1

Issue ID

UUM-34811

Regression

Yes

Crash on Transform::FlushDelayedSetDirty when undoing duplication of a certain object

--

-

Reproduction steps:
1. Open the attached user's project ("Tru..2021")
2. Open scene "Scenes/SampleScene"
3. In the scene hierarchy, expand the Canvas
4. Duplicate either of the objects inside it (CTRL + D or CMD + D)
5. Undo the duplication

Expected result: The duplication gets undone and the new object is deleted
Actual result: The Editor crashes

Reproducible with: 2021.2.0a20, 2021.3.24f1, 2022.1.0a1
Not reproducible with: 2020.3.47f1, 2021.2.0a19, 2022.2.16f1, 2023.2.0a13

Reproducible on: macOS 13.3.1 (Intel)

Stacktrace:
0x00007ff62ef1c9dd (Unity) Transform::FlushDelayedSetDirty
0x00007ff62fb58a12 (Unity) SceneTracker::FlushDirty
0x00007ff63005826c (Unity) UndoManager::PostApply
0x00007ff630052273 (Unity) UndoManager::ApplyUndo
0x00007ff63005bac7 (Unity) UndoManager::Undo
0x00007ff62fb556a0 (Unity) MenuController::ExecuteMenuItem

  1. Resolution Note:

    Between 2020.3 and 2021.3 an overhaul of the undo system changed the way Unity creates and processes undo and redo actions. The previous system used snapshots which captured the object at the point of performing undo, which had the side effect of covering up some incorrect uses of the undo system such as child objects and components not being saved to Undo.
    In 2021.3 onwards all objects that are expected to be undoable should be explicitly saved into the undo system. The fix seen later in 2022.1 onwards captures the orphaned objects and destroys them for the user as the warning seen in later versions describes. Unfortunately that change is part of another much larger overhaul and would be risky to add to 2021.3 at this point.

    A simple work around is to use the undo system as intended and explicitly record the addition of and changes to the child objects being added in the project scripts. The key to this issue is the CanvasRenderer of the ShadowRenderer object being assigned to the CanvasRenderer of the GameObject being deleted by Undo. By using UnityEditor.Undo.RecordObject(renderer, "") directly before the CanvasRenderer is assigned the child object no longer references the deleted object after undoing. See https://docs.unity3d.com/ScriptReference/Undo.html for further details on recording objects correctly within the undo system.

Comments (1)

  1. Le_Tai

    Nov 16, 2023 08:06

    For anyone running into this issue, make sure to update your Unity editor to the latest patch version. While recording the created object remove the warning in 2022+, it seem to still causes a crash in the lower patch version of 2021.3, 2022.3, 2023.1.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.