CBA_A3 icon indicating copy to clipboard operation
CBA_A3 copied to clipboard

SearchNearby Endless Loop

Open Zachary-Higgins-Attic opened this issue 3 years ago • 2 comments

Mods (complete and add to the following information):

  • Arma 3: x.xx [e.g. 1.00 stable, rc, dev]
  • CBA: fe3eba0 Make sure to reproduce the issue with only CBA on a newly created mission!

Description: CBA_fnc_SearchNearby is susceptible to an endless loop when pathing issues occur. In the excerpt below, you can see that the position is not removed until the unit is ready. If the unit does not reach its destination, it will never be ready. Therefore one unit in a group can cause this thread to stay open forever. https://github.com/CBATeam/CBA_A3/blob/release/addons/ai/fnc_searchNearby.sqf

 while {_positions isNotEqualTo []} do {
        // Update units in case of death
        private _units = (units _group) - [_leader];

        // Abort search if the group has no units left
        if (_units isEqualTo []) exitWith {};

        // Send all available units to the next available position
        {
            if (_positions isEqualTo []) exitWith {};
            if (unitReady _x) then {
                private _pos = _positions deleteAt 0;
                _x commandMove _pos;
                sleep 2;
            };
        } forEach _units;
    };

In my opinion, there should be a failsafe in this loop (maybe a timeout).

private _starttime = time;
private _timeout = 240; //???

... stuff

while {_positions isNotEqualTo [] && __starttime + _timeout > time} do {
        // Update units in case of death
        private _units = (units _group) - [_leader];

        // Abort search if the group has no units left
        if (_units isEqualTo []) exitWith {};

        // Send all available units to the next available position
        {
            if (_positions isEqualTo []) exitWith {};
            if (unitReady _x) then {
                private _pos = _positions deleteAt 0;
                _x commandMove _pos;
                sleep 2;
            };
        } forEach _units;
    };

Not sure, just need some way to break this loop if there are pathing issues.

Steps to reproduce:

  • Assign this task to group of 5 or more units. Eventually, they will get stuck.

Expected behavior:

  • Units don't get stuck... forever.

Where did the issue occur?

  • Self Hosted Multiplayer (probably everywhere)

Log Files:

  • Not applicable. No error reported.

Additional context: I will make a PR after work with my suggestion.

Zachary-Higgins-Attic avatar Apr 26 '22 18:04 Zachary-Higgins-Attic

Please review the PR. I found it was better to track each units time start and add a timeout evaluation with unitready.

Zachary-Higgins-Attic avatar Apr 27 '22 03:04 Zachary-Higgins-Attic

image

In the provided screenshot, all 4 units in group1 are not moving. Since the loop depends on them being ready before the waypoint lock is removed, this will never be complete.

Zachary-Higgins-Attic avatar May 16 '22 01:05 Zachary-Higgins-Attic

Addressed in #1547.

jonpas avatar Sep 07 '23 13:09 jonpas