Fix map editor not removing an actor properly. - #21354
Merged
Merged
Conversation
PunkPun
reviewed
Mar 9, 2024
PunkPun
left a comment
Member
There was a problem hiding this comment.
You can create actors by editing ID's. Here are the steps
- change actor's name
- undo once
- change actor's name again (making sure you don't select the actor but renaming the already selected actor)
As a cherry on top, the game will start crash when you try to undo
Exception of type `System.ArgumentException`: An item with the same key has already been added. Key: v07 Actor86
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at OpenRA.Mods.Common.Traits.EditorActorLayer.Add(EditorActorPreview preview, Boolean initialSetup) in OpenRA/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs:line 148
at OpenRA.Mods.Common.Widgets.Logic.SetActorIdAction.Undo(EditorActorPreview& actor) in OpenRA/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs:line 538
at OpenRA.Mods.Common.Widgets.Logic.EditActorEditorAction.Undo() in OpenRA/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs:line 465
at OpenRA.Mods.Common.Traits.EditorActionManager.Undo() in OpenRA/OpenRA.Mods.Common/Traits/World/EditorActionManager.cs:line 67
at OpenRA.Mods.Common.Widgets.Logic.MapEditorLogic.<>c__DisplayClass0_2.<.ctor>b__3() in OpenRA/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs:line 51```
RoosterDragon
force-pushed
the
fix-editor-delete
branch
from
March 14, 2024 18:58
fa45657 to
c5f0d5f
Compare
Member
Author
|
Thanks for the repro steps. I hadn't noticed you could switch back to the selection tab after undoing in the history. That's very sneaky! This is fixed by also updating the selection with the new preview. That seems to have done the job. Whilst I was in there I changed the history text to show both the old and new actor ID if you change it during an edit, which makes the history a bit clearer. |
PunkPun
reviewed
Mar 20, 2024
RoosterDragon
force-pushed
the
fix-editor-delete
branch
from
March 27, 2024 18:19
c5f0d5f to
4397285
Compare
If you edit an actor name, then delete the actor - it fails to be removed from the map in the editor. This is because the actor previews are keyed by ID. Editing their name edits their ID and breaks the stability of their hash code. This unstable hash code means the preview will now fail to be removed from collections, even though it's the "same" object. Fix this by making the ID immutable to ensure hash stability - this means that a preview can be added and removed from collections successfully. Now when we edit the ID in the UI, we can't update the ID in place on the preview. Instead we must generate a new preview with the correct ID and swap it with the preview currently in use.
RoosterDragon
force-pushed
the
fix-editor-delete
branch
from
March 27, 2024 18:20
4397285 to
8c8faf0
Compare
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If you edit an actor name, then delete the actor - it fails to be removed from the map in the editor. This is because the actor previews are keyed by ID. Editing their name edits their ID and breaks the stability of their hash code. This unstable hash code means the preview will now fail to be removed from collections, even though it's the "same" object.
Fix this by making the ID immutable to ensure hash stability - this means that a preview can be added and removed from collections successfully. Now when we edit the ID in the UI, we can't update the ID in place on the preview. Instead we must generate a new preview with the correct ID and swap it with the preview currently in use.
Fixes #19287