ALiVEOS / ALiVE.OS

ALiVE Open Source GPL v2
http://alivemod.com/
Other
157 stars 80 forks source link

Removing objective post-init causes script error. #727

Open E-Ledere opened 3 years ago

E-Ledere commented 3 years ago

Prerequisites

Description

Removing an objective using the "removeObjective" case in OPCOM can cause a script error to occur after the command successfully executes, specifically in the "sortObjective" case.

I have attached a test mission to this issue in which I was able to reliably replicate this problem.

Steps to Reproduce

  1. Start a mission with multiple objectives.
  2. Remove an objective during runtime.
  3. Receive script error.

Expected behavior: No script error.

Actual behavior: Script error.

aliveError.Stratis.zip Arma3_x64_2021-03-24_14-16-01.rpt.txt

DavisBrown723 commented 3 years ago

I no longer see this error if OPCOM is allowed to fully start up before executing the script.

sleep 10;

waituntil {
    (OPCOM_INSTANCES select { !([_x,"startupComplete", false] call ALiVE_fnc_hashGet) }) isequalto []
};

{
    if(([_x, "side", ""] call ALiVE_fnc_HashGet) == "WEST") then {
        _objectives = [_x, "objectives", []] call ALiVE_fnc_HashGet;
        private _id = [(_objectives # 0), "objectiveID", "empty"] call ALiVE_fnc_hashGet;
        [_x, "removeObjective", _id] call ALiVE_fnc_OPCOM;
        hint "Removing objective.";
    };
} foreach OPCOM_INSTANCES;

You can check with a manual call to sortObjectives

{
    if(([_x, "side", ""] call ALiVE_fnc_HashGet) == "WEST") then {
        [_x, "sortObjectives"] call ALiVE_fnc_OPCOM;
    };
} foreach OPCOM_INSTANCES;

Can you confirm this fixes your issue?

E-Ledere commented 3 years ago

I'm continuing to see the same problem in the same test mission, it's just not reproducible 100% of the time anymore.

It still seems fairly reproducible with this code in initServer.sqf:

sleep 10;

waituntil {
    (OPCOM_INSTANCES select { !([_x,"startupComplete", false] call ALiVE_fnc_hashGet) }) isequalto []
};

{
    if(([_x, "side", ""] call ALiVE_fnc_HashGet) == "WEST") then {
        _objectives = [_x, "objectives", []] call ALiVE_fnc_HashGet;
        private _id = [(_objectives # 0), "objectiveID", "empty"] call ALiVE_fnc_hashGet;
        [_x, "removeObjective", _id] call ALiVE_fnc_OPCOM;
        hint "Removing objective.";
    };
} foreach OPCOM_INSTANCES;
DavisBrown723 commented 3 years ago

Seems like maybe a race condition that stems from a spawned code block which makes this tougher to track down. Will look again tomorrow.