From 5b4b057ca1dd94fd518121e2a3eb7dd343d178e8 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 3 Jul 2018 20:13:06 +0200 Subject: [PATCH 1/3] don't skip next PFH if current one is removed while iterating through --- addons/common/fnc_removePerFrameHandler.sqf | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/common/fnc_removePerFrameHandler.sqf b/addons/common/fnc_removePerFrameHandler.sqf index 93846b162..8e4ae1254 100644 --- a/addons/common/fnc_removePerFrameHandler.sqf +++ b/addons/common/fnc_removePerFrameHandler.sqf @@ -29,13 +29,19 @@ if (_handle < 0 || {_handle >= count GVAR(PFHhandles)}) exitWith {}; [{ params ["_handle"]; - GVAR(perFrameHandlerArray) deleteAt (GVAR(PFHhandles) select _handle); - GVAR(PFHhandles) set [_handle, nil]; + GVAR(perFrameHandlerArray) set [GVAR(PFHhandles) select _handle select 0, {}]; - { - _x params ["", "", "", "", "", "_handle"]; - GVAR(PFHhandles) set [_handle, _forEachIndex]; - } forEach GVAR(perFrameHandlerArray); + [{ + params ["_handle"]; + + GVAR(perFrameHandlerArray) deleteAt (GVAR(PFHhandles) select _handle); + GVAR(PFHhandles) set [_handle, nil]; + + { + _x params ["", "", "", "", "", "_handle"]; + GVAR(PFHhandles) set [_handle, _forEachIndex]; + } forEach GVAR(perFrameHandlerArray); + }, _handle] call CBA_fnc_execNextFrame; }, _handle] call CBA_fnc_directCall; nil From e4316d913b395fa10fd2b522beef3c415104b3ad Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 4 Jul 2018 19:33:47 +0200 Subject: [PATCH 2/3] loop only once if multiple pfh are removed in the same frame --- addons/common/fnc_removePerFrameHandler.sqf | 37 ++++++++++++--------- addons/common/init_perFrameHandler.sqf | 1 + 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/addons/common/fnc_removePerFrameHandler.sqf b/addons/common/fnc_removePerFrameHandler.sqf index 8e4ae1254..e6a0a72a0 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,24 +24,31 @@ Author: params [["_handle", -1, [0]]]; -if (_handle < 0 || {_handle >= count GVAR(PFHhandles)}) exitWith {}; - [{ params ["_handle"]; - GVAR(perFrameHandlerArray) set [GVAR(PFHhandles) select _handle select 0, {}]; + private _index = GVAR(PFHhandles) param [_handle]; + if (isNil "_index") exitWith {false}; - [{ - params ["_handle"]; + GVAR(PFHhandles) set [_handle, nil]; + (GVAR(perFrameHandlerArray) select _index) set [0, {}]; - GVAR(perFrameHandlerArray) deleteAt (GVAR(PFHhandles) select _handle); - GVAR(PFHhandles) set [_handle, nil]; + if (GVAR(perFrameHandlersToRemove) isEqualTo []) then { + [{ + { + GVAR(perFrameHandlerArray) set [_x, objNull]; + } forEach GVAR(perFrameHandlersToRemove); - { - _x params ["", "", "", "", "", "_handle"]; - GVAR(PFHhandles) set [_handle, _forEachIndex]; - } forEach GVAR(perFrameHandlerArray); - }, _handle] call CBA_fnc_execNextFrame; -}, _handle] call CBA_fnc_directCall; + GVAR(perFrameHandlerArray) = GVAR(perFrameHandlerArray) - [objNull]; + GVAR(perFrameHandlersToRemove) = []; -nil + { + _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; 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) = []; From 96e9cdb0ca46509669b2535115478ac39aeb563e Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 4 Jul 2018 19:44:29 +0200 Subject: [PATCH 3/3] remove superfluous array --- addons/common/fnc_removePerFrameHandler.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/fnc_removePerFrameHandler.sqf b/addons/common/fnc_removePerFrameHandler.sqf index e6a0a72a0..bfc548da1 100644 --- a/addons/common/fnc_removePerFrameHandler.sqf +++ b/addons/common/fnc_removePerFrameHandler.sqf @@ -34,7 +34,7 @@ params [["_handle", -1, [0]]]; (GVAR(perFrameHandlerArray) select _index) set [0, {}]; if (GVAR(perFrameHandlersToRemove) isEqualTo []) then { - [{ + { { GVAR(perFrameHandlerArray) set [_x, objNull]; } forEach GVAR(perFrameHandlersToRemove); @@ -46,7 +46,7 @@ params [["_handle", -1, [0]]]; _x params ["", "", "", "", "", "_index"]; GVAR(PFHhandles) set [_index, _forEachIndex]; } forEach GVAR(perFrameHandlerArray); - }] call CBA_fnc_execNextFrame; + } call CBA_fnc_execNextFrame; }; GVAR(perFrameHandlersToRemove) pushBackUnique _index;