Skip to content

Commit

Permalink
don't skip next PFH if current one is removed while iterating through (
Browse files Browse the repository at this point in the history
…#950)

* don't skip next PFH if current one is removed while iterating through

* loop only once if multiple pfh are removed in the same frame

* remove superfluous array
  • Loading branch information
commy2 authored Jul 23, 2018
1 parent 8eaac30 commit d6afdf6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
35 changes: 24 additions & 11 deletions addons/common/fnc_removePerFrameHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Parameters:
_handle - The function handle you wish to remove. <NUMBER>
Returns:
None
true if removed successful, false otherwise <BOOLEAN>
Examples:
(begin example)
Expand All @@ -24,18 +24,31 @@ Author:

params [["_handle", -1, [0]]];

if (_handle < 0 || {_handle >= count GVAR(PFHhandles)}) exitWith {};

[{
params ["_handle"];

GVAR(perFrameHandlerArray) deleteAt (GVAR(PFHhandles) select _handle);
GVAR(PFHhandles) set [_handle, nil];
private _index = GVAR(PFHhandles) param [_handle];
if (isNil "_index") exitWith {false};

{
_x params ["", "", "", "", "", "_handle"];
GVAR(PFHhandles) set [_handle, _forEachIndex];
} forEach GVAR(perFrameHandlerArray);
GVAR(PFHhandles) set [_handle, nil];
(GVAR(perFrameHandlerArray) select _index) set [0, {}];

if (GVAR(perFrameHandlersToRemove) isEqualTo []) then {
{
{
GVAR(perFrameHandlerArray) set [_x, objNull];
} forEach GVAR(perFrameHandlersToRemove);

GVAR(perFrameHandlerArray) = GVAR(perFrameHandlerArray) - [objNull];
GVAR(perFrameHandlersToRemove) = [];

{
_x params ["", "", "", "", "", "_index"];
GVAR(PFHhandles) set [_index, _forEachIndex];
} forEach GVAR(perFrameHandlerArray);
} call CBA_fnc_execNextFrame;
};

GVAR(perFrameHandlersToRemove) pushBackUnique _index;
true
}, _handle] call CBA_fnc_directCall;

nil
1 change: 1 addition & 0 deletions addons/common/init_perFrameHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define DELAY_MONITOR_THRESHOLD 1 // Frames

GVAR(perFrameHandlerArray) = [];
GVAR(perFrameHandlersToRemove) = [];
GVAR(lastTickTime) = diag_tickTime;

GVAR(waitAndExecArray) = [];
Expand Down

0 comments on commit d6afdf6

Please sign in to comment.