Script error with CBA_fnc_addPerFrameHandler when used in scheduled. #230

commy2 opened this Issue Jan 9, 2016 · 3 comments


None yet

3 participants

commy2 commented Jan 9, 2016

While debuging PFHs under extreme conditions I found a problem with the function when used together with the scheduler.

0 spawn {while {true} do {systemChat str ([{[_this select 1] call CBA_fnc_removePerFramehandler}, 0, []] call cba_fnc_addPerFrameHandler)}}

Causes these to pop up randomly:

20:00:08 Error in expression <, nil];
cba_common_perFrameHandlerArray set [_handle, nil];
_newArray = [];

20:00:08   Error position: <set [_handle, nil];
_newArray = [];

20:00:08   Error Zero divisor
20:00:08 File x\cba\addons\common\fnc_removePerFrameHandler.sqf, line 15

The reason seems to be the scheduler stoping between these lines:

    _publicHandle = GVAR(PFHhandles) pushback _handle;
    _data = [_func, _delay, 0, diag_tickTime, _params, _publicHandle];
    GVAR(perFrameHandlerArray) pushBack _data;

Causing the OEF event to iterate through GVAR(PFHhandles) before GVAR(perFrameHandlerArray) is set.

@commy2 commy2 added the bug label Jan 9, 2016
@commy2 commy2 self-assigned this Jan 9, 2016
@commy2 commy2 changed the title from Script error with CBA_fnc_addPerFrameHandler when used in sheduled. to Script error with CBA_fnc_addPerFrameHandler when used in scheduled. Jan 9, 2016

Try making the "critical section" execute nonscheduled in both addPerFrameHandler and removePFH.
(There appears to be a CBA_fnc_directCall in CBA common)

commy2 commented Jan 10, 2016

That would be a solution, though direct call doesn't seem to be very optimized:

FUNC(directCall) = {
    private "_o";
    params ["_params","_code"];
    _o = SLX_XEH_DUMMY createVehicleLocal [0, 0, 0];
    ["CBA_DC", "onEachFrame", {
        params ["_args", "_code", "_o"];
        _args call _code;
        _o setDamage 1;
        ["CBA_DC", "onEachFrame"] call BIS_fnc_removeStackedEventHandler;
    }, [_params, _code, _o]] call BIS_fnc_addStackedEventHandler;

I know that there is a different method with way less overhead now, so I'll probably rewrite directCall too.


Yeah, directCall is an old remnant and could use an overhaul.

@ViperMaul ViperMaul added this to the 2.2.1 milestone Jan 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment