official-antistasi-community / A3-Antistasi

Antistasi Community Version - work in progress - Discord https://discord.com/invite/TYDwCRKnKX
https://antistasi.de
Other
226 stars 156 forks source link

Fix potential double-carry or double-drop errors under heavy script load #3293

Closed jaj22 closed 3 months ago

jaj22 commented 3 months ago

What type of PR is this.

  1. [X] Bug
  2. [ ] Change
  3. [ ] Enhancement

What have you changed and why?

It was apparently possible to fire off the drop item action twice under some real circumstances, which causes script errors. There may also have been ways to dodge some of the carry checks under similar load. This PR hardens the carry & drop actions so that they're hopefully proofed against script load issues.

Note that the github diff is a mess because the indentation changed. Actual changes are just adding sanity checks at the front of each function and wrapping the rest in isNil { code } to make sure it's not interrupted.

Edit: I suspect the reported issue was actually caused by dropItem taking a scheduler break between the detach and the A3A_carryingItem reset, which then causes the spawn in carryItem to trigger a second dropItem. The changes should fix that too anyway.

Please specify which Issue this PR Resolves.

closes #XXXX

Please verify the following and ensure all checks are completed.

  1. [X] Have you loaded the mission in LAN host?
  2. [X] Have you loaded the mission on a dedicated server?

Is further testing or are further changes required?

  1. [X] No
  2. [ ] Yes (Please provide further detail below.)

How can the changes be tested?

You can generate massive script load with something like this:

for "_i" from 1 to 100 do {
    0 spawn {
        while {isNil "test_stopSpam"} do {
             player nearRoads 100;
        };
    };
};

This should delay the addActions enough that you can fire them multiple times. Should work correctly now.