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

Script error with CBA_fnc_addPerFrameHandler when used in scheduled. #230

Closed
commy2 opened this issue Jan 9, 2016 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@commy2
Copy link
Contributor

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 = [];

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

cba>
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 Script error with CBA_fnc_addPerFrameHandler when used in sheduled. Script error with CBA_fnc_addPerFrameHandler when used in scheduled. Jan 9, 2016
@Killswitch00
Copy link
Contributor

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

@commy2
Copy link
Contributor Author

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;
    _o
};

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

@Killswitch00
Copy link
Contributor

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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants