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

Fix map editor not removing an actor properly. #21354

Merged
merged 1 commit into from Mar 28, 2024

Conversation

RoosterDragon
Copy link
Member

@RoosterDragon RoosterDragon commented Mar 6, 2024

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

Copy link
Member

@PunkPun PunkPun left a 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```

@RoosterDragon
Copy link
Member Author

RoosterDragon commented Mar 14, 2024

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.

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

@PunkPun PunkPun left a comment

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
3 checks passed
@PunkPun
Copy link
Member

PunkPun commented Mar 28, 2024

changelog

@RoosterDragon RoosterDragon deleted the fix-editor-delete branch March 29, 2024 09:55
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