-
Notifications
You must be signed in to change notification settings - Fork 150
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
Conversation
Q: What happens if the removePFH function is called twice with the same handle in the same frame (deleting already removed PFH waiting to be cleaned up NextFrame)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code wise looks good. Didn't test tho ._.
@@ -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, {}]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
GVAR(PFHhandles) set [_handle, nil]; | ||
|
||
{ | ||
_x params ["", "", "", "", "", "_handle"]; |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
I like the elegance, though running through it in my head I'm also not sure this isn't still broken as per commy's comment above. The way it is currently, I believe that if the function is called n times in the same frame for the same handler, the next n - 1 handlers would also be deleted. My first thought: My next thought: |
I like the base idea over what I have done before. but what I dislike is that you run over every PFH Multiple times when more than 1 PFH got remove per frame. so you would have both systems combined in a way. |
@SilentSpike Can you think of a way to potential bring this issue about? Reading the code again after sleep, everything looks fine, even if the same ID is removed twice.
This almost never happens though. Removing multiple PFH in the same frame. |
I still prefer that over the alternative of executing some code every Frame even if it's not needed 99% of the time. |
it does that is why I bringing this up. and also the check happens I frame After the PFH is removed
then you don't read my post correctly. I sad this is a better solution but I think that it could be more optimized. in the way that we could combine both ideas and use the execNextFrame for the base removal but still save the indices that are deleted |
[{ | ||
params ["_handle"]; | ||
|
||
GVAR(perFrameHandlerArray) deleteAt (GVAR(PFHhandles) select _handle); |
There was a problem hiding this comment.
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?).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
What about this? Tested it a bit with laptop, and it seems to work as expected. |
|
||
GVAR(perFrameHandlerArray) deleteAt (GVAR(PFHhandles) select _handle); | ||
GVAR(PFHhandles) set [_handle, nil]; | ||
if (GVAR(perFrameHandlersToRemove) isEqualTo []) then { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing !
?
There was a problem hiding this comment.
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
that is the same way I have it implemented. like it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
we've rewritten this fix many times but this one is the best; no run-time performance hit |
* origin/master: XEH - Compatiblity for Encore (1.84) (#953) indicate settings that need a mission restart (#894) don't skip next PFH if current one is removed while iterating through (#950) change color of name of temporarily changed settings (#952) handle input gracefully in keybinding editKey ui function (#951) Update fnc_deleteEntity.sqf (#949)
When merged this pull request will:
{}
, then delete NextFrame (guaranteed to happen outside of iterating through the array that is modified)Needs testing, I won't have access to Arma this and the next week.