diff --git a/addons/common/fnc_removePerFrameHandler.sqf b/addons/common/fnc_removePerFrameHandler.sqf index 93846b162..bfc548da1 100644 --- a/addons/common/fnc_removePerFrameHandler.sqf +++ b/addons/common/fnc_removePerFrameHandler.sqf @@ -9,7 +9,7 @@ Parameters: _handle - The function handle you wish to remove. Returns: - None + true if removed successful, false otherwise Examples: (begin example) @@ -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 diff --git a/addons/common/init_perFrameHandler.sqf b/addons/common/init_perFrameHandler.sqf index ce645dfde..1b45f14f9 100644 --- a/addons/common/init_perFrameHandler.sqf +++ b/addons/common/init_perFrameHandler.sqf @@ -6,6 +6,7 @@ #define DELAY_MONITOR_THRESHOLD 1 // Frames GVAR(perFrameHandlerArray) = []; +GVAR(perFrameHandlersToRemove) = []; GVAR(lastTickTime) = diag_tickTime; GVAR(waitAndExecArray) = [];