Skip to content

Fix map editor not removing an actor properly. - #21354

Merged
PunkPun merged 1 commit into
OpenRA:bleedfrom
RoosterDragon:fix-editor-delete
Mar 28, 2024
Merged

PunkPun merged 1 commit into
OpenRA:bleedfrom
RoosterDragon:fix-editor-delete

Conversation

@RoosterDragon

@RoosterDragon RoosterDragon commented Mar 6, 2024

Copy link
Copy Markdown
Member

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

@PunkPun PunkPun left a comment

Copy link
Copy Markdown
Member

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```

@RoosterDragon

RoosterDragon commented Mar 14, 2024

Copy link
Copy Markdown
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.

Comment thread OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs Outdated
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.

@PunkPun PunkPun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@PunkPun
PunkPun merged commit 799c4c9 into OpenRA:bleed Mar 28, 2024
@PunkPun

PunkPun commented Mar 28, 2024

Copy link
Copy Markdown
Member

changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'zombie' actor in map editor that does not get removed on deletion

2 participants