HomeWildfire Games

Fix IDLE-related infinite loops by moving stateful calls to IDLE.timer.
AuditedrP22475

Description

Fix IDLE-related infinite loops by moving stateful calls to IDLE.timer.

The game currently has several infinite loops, and the stack trace is always a variation on the same pattern that units go through IDLE as a default state, immediately try another order (possibly entering a new state), failing, and goes back to IDLE.

IDLE.Timer is a general workaround for this issue. It wastes a turn every time a unit goes idle, so should a better solution be found for the general problem of infinite loops in UnitAI, it should be removed.

This revert rP22059 which was intended as a safety net, but couldn't protect againt infinite loops between two different states.

Fixes #5460

Differential Revision: https://code.wildfiregames.com/D2041

Event Timeline

Silier added a subscriber: Silier.Jul 19 2019, 3:17 PM
Silier added inline comments.
/ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
1464

this comment is no more valid since we are not in enter anymore

1470

the same as L1464

https://wildfiregames.com/forum/index.php?/topic/27214-borg-expansion-pack-mod-implementation-in-0ad-alpha-24-release/&do=findComment&comment=388029
We might check for this.isIdle in the LosRangeUpdate but I'm not sure that would not introduce other side effects. And setting up a MWE for this specific case is not too easy ;)

Silier added a comment.EditedNov 13 2019, 10:45 AM

If this.idle is false in LosRangeUpdate, simply call FindNewTargets, but because there can be multiple events while this.idle is false on LosRangeUpdate, there need to be some boolean which would ensure we call FindNewTargets just once and then we are safe to fall back to default behaviour.

Or another more safer approach is to ingore range updates in IDLE state while unit is not true idle, what looks more likely what we want.

Notice that while that events would be ingored, entities will be taken into account when timer fires up.

I am glad we came to the same conclusion, albeit you expressed it clearly, and I had trouble transferring it from my mind to here ;)

elexis raised a concern with this commit.Nov 14 2019, 4:55 PM
elexis added a subscriber: elexis.

See above

This commit now has outstanding concerns.Nov 14 2019, 4:55 PM
Freagarach accepted this commit.Dec 8 2019, 1:34 PM

@elexis I will accept on your behalf, since you raised a concern on my behalf. (If not appropriate, please notify me.)
The concern was fixed in rP23216.

elexis removed an auditor: elexis.Dec 8 2019, 1:45 PM

Thanks for the fix!

All concerns with this commit have now been addressed.Dec 8 2019, 1:45 PM