Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track View: Major fix for GHI# 11500 #18538

Merged

Conversation

Aleks-Starykh-TR
Copy link
Contributor

@Aleks-Starykh-TR Aleks-Starykh-TR commented Dec 5, 2024

What does this PR do?

Closes #11500
Closes #17372

  • Fixes the ambiguous warning "Can't get component (type: EditorSequenceComponent, addr: ?) entity ID as it is not attached to an entity yet!" in the Component::GetEntityId() generated in the EditorSequenceComponent::RemoveEntityToAnimate(() while destroying an instance when sanitizing a prefab DOM;
    • No side-effects.

--

  • Fixes the ambiguous warning "The dirty entity has no owning instance." in the PrefabPublicHandler::GenerateUndoNodesForEntityChangeAndUpdateCache() generated while destroying an instance when sanitizing a prefab DOM;
    • This also meant that undo state was broken, which could spoil prefab template operations;
    • This occurred only when destructor for EditorSequenceComponent: was called before the destructor of the linked EditorSequenceAgentComponent; note that order of entities / components destruction is randomized, - I believe this depends on randomly generated Entity Ids and Component Ids and hence their positions in hash-tables, - for example I have two seemingly same level prefabs, differing only in entity aliases and components, which are randomly generated, and one of these was misbehaving;
    • So, in randomized destruction order this also broke the prefab loading / saving pipeline due to the EditorSequenceComponent::RemoveEntityToAnimate() was called second time from undo chain and thus was calling the EditorSequenceAgentComponent::DisconnectSequence() second time .
    • The first variant of a fix was removing the CAnimAzEntityNode containing the removedEntityId after calling the RemoveEntityToAnimate() from the EditorSequenceComponent destructor, and thus disconnecting this sequence component with that removedEntityId entity and destroying the EditorSequenceAgentComponent , yet this could introduce misbehaviour in the governing code which neglects calling AddEntityToAnimate() / RemoveEntityToAnimate()
    • The final fix is in temporary suppressing undo / redo during the EditorSequenceAgentComponent destruction in the EditorSequenceAgentComponent::DisconnectSequence(), as it this component is constructed not through the normal pipeline (designed for direct user actions evaluation). In order to temporary suppress undo / redo for this specific operation the commit 191e5cf :
      • adds the new API to maintain "ignored entities list",
      • adds checking this list when attempting to add dirty entities,
      • and then uses this new API bracketing the the 'normal' codepath for the EditorSequenceAgentComponent destruction in the EditorSequenceAgentComponent::DisconnectSequence().

--

  • Also fixes the crash on invalid pointer in CAnimSequence::RemoveNode() moving node destruction down below the node pointer usage.
    • Prior to this fix, calling the CAnimSequence::RemoveNode(IAnimNode* node) code first destructed the object erasing a vector element with the intrusive_ptr<IAnimNode>, and then attempted to use the now invalid node pointer;
    • The commit a991923 also adds a "TODO" comment to the identical code implementation of the CUiAnimSequence::RemoveNode(), changing and testing of which is out of scope for the current WIP.
    • This method was used in the previous version of the fix described above now used in a fix described below;
      --

How was this PR tested?

Repro steps of the issue #11500 with the Camera2 and the Seq entities repeated (numerously) under Windows:
a TestLevel with a Camera2 and a Seq entities containing (correctly linked EditorSequenceAgentComponent and EditorSequenceComponent respectively), - are now correctly saved an loaded.
Detached sequence entities were never noted in this scenario.

What is not done yet?

  • When instantiating a prefab which was previously (with earlier code versions) saved with a spoiled (empty) "Parent Entity" sentence in the TransformComponent of a sequence entity, such prefab is still loaded wrongly;
    I believe fixing this would be helpful, as in most practical cases the AssetBuilder will rebuild a buggy prefab into a correct spawnable - see PR Track View: Optional fix for GHI #11500: fix prefabs previously stored with invalid entity parents. #18548.
  • The problem also noted with incorrect structure of an in-memory template for a prefab recently created from a pair of Camera2 and a Seq entities in a level:
    • If the newly created prefab is deleted from the level, and then re-instantiated, it is instantiated with the "torn-off" Seq entity, because the cached in-memory DOM template is used, and this one is somehow asynchronously spoiled (the Seq entity forgets the correct container entity alias in the "Parent Entity" statement).
    • If a level is saved / reloaded or another level is loaded (thus releasing cached in-memory templates), the newly created prefab is instantiated correctly.

moving node destruction down below node ptr usage

Signed-off-by: Aleks Starykh <[email protected]>
also seems to fix serialization of the EditorSequenceAgentComponent

Signed-off-by: Aleks Starykh <[email protected]>
@lsemp3d lsemp3d added feature/trackview This item is related to the Trackview and cinematic feature. sig/content Categorizes an issue or PR as relevant to SIG Content. labels Dec 5, 2024
Copy link
Contributor

@guillaume-haerinck guillaume-haerinck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, its crazy to think that this got broken for so long. When I did fixes in the ScriptCanvas logger and wasn't able to figure out the code, using breakpoints in Lumberyard helped a ton to understand what broke it/what would be the proper fix, might be worth doing that here as well

Move the TODO comment to the CUiAnimSequence::RemoveNode().

Signed-off-by: Aleks Starykh <[email protected]>
…dability

Also revert to safer (minimal) fix for the bug generating ambiguous warning and disrupting a (level) prefab loading.
The reverted change thoroughly commented with "TODO (AnimSequence linking)" rags

Signed-off-by: Aleks Starykh <[email protected]>
@guillaume-haerinck
Copy link
Contributor

A bit too much TODO code for my taste but given that without that the trackview is almost completely broken it make sense to bring the feature back, thanks for looking at it !

…omments and code prototypes

Signed-off-by: Aleks Starykh <[email protected]>
@Aleks-Starykh-TR Aleks-Starykh-TR requested a review from a team as a code owner December 12, 2024 12:50
@Aleks-Starykh-TR Aleks-Starykh-TR changed the title Track View: Partial fix (1) for GHI# 11500 Track View: Major fix for GHI# 11500 Dec 12, 2024
@Aleks-Starykh-TR
Copy link
Contributor Author

@lsemp3d : You have previously approved it, but I've re-requested your review after code changes.

Copy link
Contributor

@nick-l-o3de nick-l-o3de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the alternative would have been to call RemoveDirtyEntity but not having it enter the undo stack and be captured in the first place really is preferable. The same API might be useful later for creating temporary visualization entities that must not be saved or persisted.

@Aleks-Starykh-TR
Copy link
Contributor Author

@nick-l-o3de

I guess the alternative would have been to call RemoveDirtyEntity but not having it enter the undo stack and be captured in the first place really is preferable. The same API might be useful later for creating temporary visualization entities that must not be saved or persisted.

The problem is that calling RemoveDirtyEntity before the standard code-flow request to the AzToolsFramework::EntityCompositionRequests::RemoveComponents does not help, as the Entity is added to a dirty list deep inside this standard code-flow.

@nick-l-o3de nick-l-o3de merged commit 582e89d into o3de:development Dec 20, 2024
3 checks passed
@nick-l-o3de
Copy link
Contributor

Excellent work on this PR

@Aleks-Starykh-TR Aleks-Starykh-TR deleted the astarykh/partial_fix_for_GHI_11500 branch December 23, 2024 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/trackview This item is related to the Trackview and cinematic feature. sig/content Categorizes an issue or PR as relevant to SIG Content.
Projects
Status: Done
4 participants