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

Common - Prevent endless loop with waitAndExec #1209

Merged
merged 3 commits into from
Sep 9, 2019
Merged
Changes from all commits
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
12 changes: 8 additions & 4 deletions addons/common/init_perFrameHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@

#include "script_component.hpp"

#define DELAY_MONITOR_THRESHOLD 1 // Frames

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

GVAR(waitAndExecArray) = [];
GVAR(waitAndExecArrayIsSorted) = false;
GVAR(nextFrameNo) = diag_frameno + 1;
// PostInit can be 2 frames after preInit, need to manually set nextFrameNo, so new items get added to buffer B while processing A for the first time:
GVAR(nextFrameBufferA) = [[[], {GVAR(nextFrameNo) = diag_frameno;}]];
GVAR(nextFrameBufferA) = [];
GVAR(nextFrameBufferB) = [];
GVAR(waitUntilAndExecArray) = [];

Expand All @@ -23,6 +20,13 @@ GVAR(waitUntilAndExecArray) = [];
private _tickTime = diag_tickTime;
call FUNC(missionTimePFH);

// frame number does not match expected; can happen between pre and postInit, save-game load and on closing map
// need to manually set nextFrameNo, so new items get added to buffer B and are not executed this frame
if (diag_frameno != GVAR(nextFrameNo)) then {
TRACE_2("frame mismatch",diag_frameno,GVAR(nextFrameNo));
GVAR(nextFrameNo) = diag_frameno;
};

// Execute per frame handlers
{
_x params ["_function", "_delay", "_delta", "", "_args", "_handle"];
Expand Down