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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions addons/common/fnc_removePerFrameHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}];
Copy link
Contributor

Choose a reason for hiding this comment

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

Fun fact. call doesn't exit early if it has no code. It will actually really build a callstack and everything required. And then execute the empty code and exit right after.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't have implemented it any other way tbh. For simplicity.


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

GVAR(perFrameHandlerArray) deleteAt (GVAR(PFHhandles) select _handle);
Copy link
Contributor

Choose a reason for hiding this comment

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

@commy2 Yeah reading again after a sleep I don't think it would break anymore (since this line becomes deleteAt nil on any duplicated calls - which I assume won't error?).

Copy link
Contributor

Choose a reason for hiding this comment

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

The only exception would be, if you were to remove the same handle twice in the same frame and also addEventHandler in the next frame, would it be possible that the same index (_handle) could be refilled in between the two execNextFrame calls? Resulting in the newly added EH being deleted immediately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is all changed now.

GVAR(PFHhandles) set [_handle, nil];

{
_x params ["", "", "", "", "", "_handle"];
Copy link
Contributor

Choose a reason for hiding this comment

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

reusing _handle here looks confusing to some people. But these people don't look at CBA code anyway.

(I pressed send review and wanted to submit the comment after that.. But who could've guessed that the comment is discarded when you submit the review.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just indented the previous code. The function is simple enough I'd say.

GVAR(PFHhandles) set [_handle, _forEachIndex];
} forEach GVAR(perFrameHandlerArray);
}, _handle] call CBA_fnc_execNextFrame;
}, _handle] call CBA_fnc_directCall;

nil