Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 24 additions & 11 deletions addons/common/fnc_removePerFrameHandler.sqf
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing ! ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah never mind I see how it works now, because it's next frame and only runs once due to this

[{
{
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
Expand Up @@ -6,6 +6,7 @@
#define DELAY_MONITOR_THRESHOLD 1 // Frames

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

GVAR(waitAndExecArray) = [];
Expand Down