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
Fix map editor not removing an actor properly. #21354
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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```
fa45657
to
c5f0d5f
Compare
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. |
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.
4397285
to
8c8faf0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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