Skip to content

Fix dynamic dialogue race condition with CustomUnits DEPLOY actor#710

Open
CWolfs wants to merge 2 commits intodevelopfrom
fix/MC-708-deploy-actor-race-condition
Open

Fix dynamic dialogue race condition with CustomUnits DEPLOY actor#710
CWolfs wants to merge 2 commits intodevelopfrom
fix/MC-708-deploy-actor-race-condition

Conversation

@CWolfs
Copy link
Copy Markdown
Owner

@CWolfs CWolfs commented Apr 11, 2026

Summary

Changes

  • BindAbstractActorToBindingKey() now matches actors by pilot identity (same pattern as GetSpeakerUnit and commander binding), with bounds-checked index fallback
  • Both while loops in HandleDeadActorFromDialogueContent() have iteration guards scaled to lance size
  • HandleFallback removes stale BoundAbstractActorsFullIndex entries on Darius fallback
  • RebindDeadUnitCastDef now wraps bindKey with GetDynamicCastDefIDFromBindKey() when calling HandleFallback

CWolfs added 2 commits April 11, 2026 12:46
…708)

BindAbstractActorToBindingKey() used positional indexing to map binding
keys to actors. When CustomUnits injects a temporary DEPLOY actor at
position 0 of the player lance, all indices shift by one, binding the
wrong actors to dialogue cast keys. After deployment, the dead DEPLOY
actor causes an infinite loop in HandleDeadActorFromDialogueContent().

Changes:
- Match actors by pilot identity in BindAbstractActorToBindingKey(),
  with bounds-checked index fallback
- Add iteration guards to both dead-actor rebinding loops in
  HandleDeadActorFromDialogueContent(), scaling with lance size
- Clean up stale BoundAbstractActorsFullIndex entries on Darius fallback
  to prevent re-binding dead actors

Also fixes #709: RebindDeadUnitCastDef passed a bare bindKey to
HandleFallback without the castDef_ prefix, so IsBindableRandomCastDefID
always returned false on the rebinding path. DynamicCastDefs and
BoundAbstractActorsFullIndex were never updated during fallback, causing
an infinite loop when all lance pilots are dead — even without CU.
The PureRandom dead-actor loop sampled positions with replacement,
meaning it could repeatedly pick the same dead pilot and miss a live
one. With the iteration guard this caused a ~24% false Darius fallback
on a 4-pilot lance with 1 survivor.

Shuffle positions using Fisher-Yates so each pilot is tried exactly
once, guaranteeing a survivor is found if one exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant