Page MenuHomeFeedback Tracker

Broken? object reference.
Closed, ResolvedPublic

Description

I was working on a Script to iterate through an array of particle spawners. Since i had to change something, i converted it to a nested array instead of previously, a simple array ob objects.

I did a testrun while i havent converted the full function to take an nested array into account and instead, it was still partly handling it like a simple array.

The testrun, once i ran the function, resulted in an error (see additional Information).

While trying to debug, i noticed that the array i was iterrating trhough had values in it that seem to be of an unusual format.

CVO_Storm_Local_PE_Spawner_array:

[
[2bb164a0100# 163978: sign_arrow_large_f.p3d,"Debug_Helper"],
[00007FF7AB13E630,".somelongstring..",1],
[00007FF7AB13E630,".somelongstring..",1]
]

For debugging, and to figure out what i did wrong, i tried to select #0 on it, but the debug console didnt return anything.

Details

Severity
None
Resolution
Not A Bug
Reproducibility
N/A
Operating System
Windows 10 x64
Category
Scripting
Steps To Reproduce

Run this: Dependency on CBA

The function in the state when it is causing the issue:
https://github.com/PulsarNeutronStar/CVO-Sandstorm/blob/52b6813e7b1d86838c34a031adab3f4c9f517bb7/addons/storm/functions/fn_particle_remote.sqf

/*
 * Author: [Zorn]
 * Function to apply the Particle Effects - Handles creation, deletion and adjustment of intensity of particlespawners on each client locally.
 * Intensity will be regulated simply by dropInterval (The bigger the number, the less particles)
 * If the same Effect has already been called, it will instead adjust the already existing PE spawner.
 * If _intensityTarget == 0, the function will ether exit in case the spawner doesnt exist already or transition the spawner to 0 intensity and afterwards, the spawner will be deleted.  
 *
 * Arguments:
 * 0: _EffectName           <STRING> CfgCloudlet Classname of the desired Particle Effect. 
 * 1: _intensityTarget      <Number> 0..1 Intensity of Effect with 1 having the strongest Effect. 
 * 2: _duration             <Number> in seconds. Defines the Duration of the Transition. 
 *
 * Return Value:
 * none - intended to be remoteExecCall -> returns JIP Handle
 *
 * Note: 
 *
 * Example:
 *
 * ["CVO_PE_Leafes", 600, 0.75] remoteExecCall ["cvo_storm_fnc_particle_remote",0, _jip_handle_string];
 * ["CVO_PE_Leafes", 600]       remoteExecCall ["cvo_storm_fnc_particle_remote",0, _jip_handle_string];
 * ["CLEANUP"]                  remoteExecCall ["cvo_storm_fnc_particle_remote",0, _jip_handle_string];
 * ["CVO_PE_Leafes"]            call cvo_storm_fnc_particle_remote
 * ["CLEANUP"]                  call cvo_storm_fnc_particle_remote
 * 
 * Public: No
 */

#define COEF_SPEED 5
#define COEF_WIND  0.2
#define PFEH_ATTACH_DELAY 0
#define PFEH_INTENSITY_DELAY 4 // _duration /  PFEH_INTENSITY_DELAY == _delay
#define DROP_INTERVAL_MIN 20



if (!hasInterface) exitWith {};

params [
    ["_effectName",        "",       [""]],
    ["_duration",         300,        [0]],
    ["_intensityTarget",    0,        [0]]
];

if ( _effectName isEqualTo "CLEANUP")  exitWith {
    if ( missionNamespace getVariable ["CVO_Debug", false] ) then {   CVO_Storm_Local_PE_Spawner_array deleteAt 0;};
    {  
        [_x#1] call cvo_storm_fnc_particle_remote;
    } forEach CVO_Storm_Local_PE_Spawner_array;
};

if ( _effectName isEqualTo "")  exitWith {};
if (_intensityTarget < 0 )      exitWith {};
if (_duration    isEqualTo  0)  exitWith {};

if (isNil "CVO_Storm_Local_PE_Spawner_array") then {
    CVO_Storm_Local_PE_Spawner_array = [];

    // Adds Debug_Helper Object (arrow)
    if (missionNamespace getVariable ["CVO_Debug", false]) then {
            _helper = createVehicleLocal [ "Sign_Arrow_Large_F", [0,0,0] ];
            CVO_Storm_Local_PE_Spawner_array pushback [_helper, "Debug_Helper"];
    };

    // Start pfEH to re-attach all Particle Spawners according to player speed & wind.
    // watch CVO_particle_isActive, if inactive, delete particle spawners and pfEH

    private _codeToRun = {
        //_SpeedVector vectorDiff _windVector
        private _player = vehicle ace_player;  
        private _relPosArray = (( velocityModelSpace _player ) vectorMultiply COEF_SPEED) vectorDiff (( _player vectorWorldToModel wind ) vectorMultiply COEF_WIND);
        _relPosArray set [2, (_relPosArray#2) + 1 ];
        { _x attachTo [_player, _relPosArray]; } forEach CVO_Storm_Local_PE_Spawner_array;
    };
    private _exitCode  = { 
    diag_log "reAttach pfEH Exit";
        { deleteVehicle _x } forEach CVO_Storm_Local_PE_Spawner_array; 
        CVO_Storm_Local_PE_Spawner_array = nil;  
    };

    private _condition = { ( missionNameSpace getVariable ["CVO_particle_isActive", false] ) || ( count CVO_Storm_Local_PE_Spawner_array > 0 ) };
    private _delay = PFEH_ATTACH_DELAY;

    [{
        params ["_args", "_handle"];
        _args params ["_codeToRun", "_exitCode", "_condition"];

        if ([] call _condition) then {
            [] call _codeToRun;
        } else {
            _handle call CBA_fnc_removePerFrameHandler;
            [] call _exitCode;
        };
    }, _delay, [_codeToRun, _exitCode, _condition]] call CBA_fnc_addPerFrameHandler;
};

// Defines custom Variablename as String 
// missionNameSpace has only lowercase letters

private _spawnerName = toLower (["CVO_Storm_Particle_",_effectName,"_particlesource"] joinString "");

////////////////////////////////////////////////////////////////////////////////////////////////////
// Check if a spawner of that type already exists, 
// if not, create, setParticleClass, store as array [_obj,_name,_intensity] and add it to the array.
// if already exists, take previous intensity and set as start inensity. 
////////////////////////////////////////////////////////////////////////////////////////////////////

private _intensityStart = 0;
private "_spawner";
private _index = CVO_Storm_Local_PE_Spawner_array findIf { _x#1 isEqualTo _spawnerName };

private _dropIntervalStart = DROP_INTERVAL_MIN;
private _dropIntervalMax = ([_effectName] call BIS_fnc_getCloudletParams) select 2; // #0 setParticleParams, #1 setParticleRandom, #2 setDropInterval
private _dropIntervalTarget = linearConversion [0, 1, _intensityTarget, _dropIntervalStart, _dropIntervalMax, true];


if (_index == -1) then {

    _spawner = createVehicleLocal ["#particlesource", [0,0,0]];
    _spawner setParticleClass _effectName;

    CVO_Storm_Local_PE_Spawner_array pushback [_spawner,_spawnerName, _intensityTarget ];

} else {
    _spawnerArray = CVO_Storm_Local_PE_Spawner_array select _index;
    _spawner = _spawnerArray#0; 
    _intensityStart = _spawnerArray#2;
    _dropIntervalStart = linearConversion [0, 1, _intensityTarget, DROP_INTERVAL_MIN, _dropIntervalMax, true];
};


////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// Particle Intensity will simply be adjusted over time via setDropInterval /////////////
///////////// Maybe in Future, Intensity could be applied via colorAlpha, Size, ...    /////////////
///////////// Problem: bad solution solution for non-dust-like particles like leafes   /////////////
///////////// Therefore, for now, particle quantitiy has been chosen as the regulator  /////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

private _startTime = time;
private _endTime = _startTime + _duration;


//// params inside the pfEH
private _parameters = [ _spawner, _startTime, _endTime, _dropIntervalStart, _dropIntervalTarget, _intensityTarget  ];

private _codeToRun = {
    params [ "_spawner", "_startTime", "_endTime", "_dropIntervalStart", "_dropIntervalTarget", "_intensityTarget"  ];
    _drop = linearConversion [ _startTime, _endTime, time, _dropIntervalStart, _dropIntervalTarget ];
    _spawner setDropInterval _drop;
}; 

private _exitCode = {   
    params [ "_spawner", "_startTime", "_endTime", "_dropIntervalStart", "_dropIntervalTarget", "_intensityTarget"  ];
    diag_log "Transition pfEH Exit";
    _spawner setDropInterval  _dropIntervalTarget; 
    if ( _intensityTarget isEqualTo 0) then {
        diag_log "Transition pfEH Exit - Intensity == 0 -> Spawner Deleted";
        CVO_Storm_Local_PE_Spawner_array = CVO_Storm_Local_PE_Spawner_array - [_spawner];   
        deleteVehicle _spawner;
    };
};

private _condition = {  _this#2 >= time };

private _delay = _duration / PFEH_INTENSITY_DELAY;

[{
    params ["_args", "_handle"];
    _args params ["_codeToRun", "_parameters", "_exitCode", "_condition"];

    if (_parameters call _condition) then {
        _parameters call _codeToRun;
    } else {
        _handle call CBA_fnc_removePerFrameHandler;
        _parameters call _exitCode;
    };
}, _delay, [_codeToRun, _parameters, _exitCode, _condition]] call CBA_fnc_addPerFrameHandler;


////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////// TODO: _spawner objects dont have the setVariables during testing?
////// Therefore, Cleanup and "adjust existing PE doesnt work yet
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
Additional Information
 1:37:55 "[CVO][STORM](LOG)(fnc_remote_ppEffect) - _existsVar : false"
 1:37:55 "[CVO][STORM](Error)(fnc_ppEffect_apply) - Success: _PP_effect_Name CVO_FG_Storm - _duration 60 - _intensity 1"
 1:37:55 Error in expression <getPos (CVO_Storm_Local_PE_Spawner_array>
 1:37:55   Error position: <getPos (CVO_Storm_Local_PE_Spawner_array>
 1:37:55   Error getpos: Type Array, expected Object,Location
 1:37:55  ➥ Context: 	[] L24 (/DEV_TOOLS/functions/general/fn_addSchd.sqf)
	[] L63 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L69 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L66 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L66 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L1 ()

 1:37:55 Error in expression <ay set [2, (_relPosArray#2) + 1 ];
{ _x attachTo [_player, _relPosArray]; } forE>
 1:37:55   Error position: <attachTo [_player, _relPosArray]; } forE>
 1:37:55   Error attachto: Type Array, expected Object
 1:37:55 File z\cvo_storm\addons\storm\functions\fn_particle_remote.sqf..., line 73
 1:37:55  ➥ Context: 	[] L245 (/x/cba/addons/common/XEH_postInit.sqf)
	[] L38 (x\cba\addons\common\init_perFrameHandler.sqf)
	[] L34 (x\cba\addons\common\init_perFrameHandler.sqf)
	[] L36 (x\cba\addons\common\init_perFrameHandler.sqf)
	[] L88 (z\cvo_storm\addons\storm\functions\fn_particle_remote.sqf)
	[] L89 (z\cvo_storm\addons\storm\functions\fn_particle_remote.sqf)
	[] L73 (z\cvo_storm\addons\storm\functions\fn_particle_remote.sqf)
	[] L73 (z\cvo_storm\addons\storm\functions\fn_particle_remote.sqf)

 1:37:55 Error in expression <getPos (CVO_Storm_Local_PE_Spawner_array>
 1:37:55   Error position: <getPos (CVO_Storm_Local_PE_Spawner_array>
 1:37:55   Error getpos: Type Array, expected Object,Location
 1:37:55  ➥ Context: 	[] L24 (/DEV_TOOLS/functions/general/fn_addSchd.sqf)
	[] L63 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L69 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L66 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L66 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L1 ()

The RPT is exensively long because this script starts a pfEH, therefore, here is the snippet of the error message *i think* is related.

Event Timeline

mrzorn created this task.EditedMar 4 2024, 2:17 AM

the line i changed that might have stopped the error from happening. (same line as error message)
https://github.com/PulsarNeutronStar/CVO-Sandstorm/blob/52b6813e7b1d86838c34a031adab3f4c9f517bb7/addons/storm/functions/fn_particle_remote.sqf#L73

another line i changed at the same time but i dont think thats responsible for the broken data.
https://github.com/PulsarNeutronStar/CVO-Sandstorm/blob/52b6813e7b1d86838c34a031adab3f4c9f517bb7/addons/storm/functions/fn_particle_remote.sqf#L158

all the changes, something here caused the array to not break anymore
https://github.com/PulsarNeutronStar/CVO-Sandstorm/commit/e0ad1bedb749fe1630739fd364e001fa2c1dab29

mrzorn added a comment.Mar 4 2024, 2:20 AM

TestMission i was running: Get in the vehicle & activate the first waypoint.

mrzorn updated the task description. (Show Details)Mar 4 2024, 2:27 AM
mrzorn edited Steps To Reproduce. (Show Details)
mrzorn updated the task description. (Show Details)
mrzorn added a comment.Mar 4 2024, 2:31 AM

If there is something unclear please feel free to ask for clarification - apologies if the report is a bit messy, its late night but i wanted to get the issue out there while i have everything at hand.

mrzorn added a comment.Mar 4 2024, 3:08 AM

I just started my PC and a script code that did not work before is now working.

I played an A3 event earlier today that was having quite some script errors. i restarted the game in between but didnt restart the game itself. i assume something wierd happend that got stored in cache that might have caused the issue?!

mrzorn added a comment.Mar 4 2024, 4:04 PM

16:03:02 Error in expression <#line 1 "new_1.sqf"
[[1bf183f0100# 163978: sign_arrow_large_f.p>
16:03:02   Error position: <bf183f0100# 163978: sign_arrow_large_f.p>
16:03:02   Error Missing ]
16:03:02 File new_1.sqf..., line 1
16:03:02  ➥ Context: 	[] L81 (DBUG\functions\console\exec\fn_exec.sqf)
	[] L81 (DBUG\functions\console\exec\fn_exec.sqf)
 <- 	[] L24 (/DEV_TOOLS/functions/general/fn_addSchd.sqf)
	[] L61 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L55 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L57 (DBUG\functions\general\EHs\fn_eachFrame.sqf)
	[] L77 (DBUG\functions\console\exec\fn_exec.sqf)
	[] L80 (DBUG\functions\console\exec\fn_exec.sqf)
mrzorn added a comment.Mar 4 2024, 4:15 PM

I think i was able to isolate the issue:

testArray = [];
_obj = createVehicleLocal ["#particlesource", [0,0,0]];
testArray pushback [_obj, "somedata1", "someOtherData1"];

_obj = createVehicleLocal ["#particlesource", [0,0,0]];
testArray pushback [_obj, "somedata2", "someOtherData3"];

_obj = createVehicleLocal ["#particlesource", [0,0,0]];
testArray pushback [_obj, "somedata2", "someOtherData3"];

testArray // [[164337: <no shape>,"somedata1","someOtherData1"],[164338: <no shape>,"somedata2","someOtherData3"],[164339: <no shape>,"somedata2","someOtherData3"]]

When i take the Value of the array and try to use the raw data and select the first entry, ill recieve the following error message: (like above)
When I reference the globalVar assosiated with it, it works, though.

Leopard20 closed this task as Resolved.Mar 4 2024, 4:23 PM
Leopard20 claimed this task.
Leopard20 added a subscriber: Leopard20.

I think i was able to isolate the issue:

testArray = [];
_obj = createVehicleLocal ["#particlesource", [0,0,0]];
testArray pushback [_obj, "somedata1", "someOtherData1"];

_obj = createVehicleLocal ["#particlesource", [0,0,0]];
testArray pushback [_obj, "somedata2", "someOtherData3"];

_obj = createVehicleLocal ["#particlesource", [0,0,0]];
testArray pushback [_obj, "somedata2", "someOtherData3"];

testArray // [[164337: <no shape>,"somedata1","someOtherData1"],[164338: <no shape>,"somedata2","someOtherData3"],[164339: <no shape>,"somedata2","someOtherData3"]]

When i take the Value of the array and try to use the raw data and select the first entry, ill recieve the following error message: (like above)
When I reference the globalVar assosiated with it, it works, though.

2bb164a0100# 163978: sign_arrow_large_f.p3d,"Debug_Helper"

That's not an object. That's just a string representation of the object, i.e. it's just a meaningless text, and there's no way to get the object from that text. You must save the object into a variable and use the variable instead.

Leopard20 changed Resolution from Open to Not A Bug.Mar 4 2024, 4:23 PM
mrzorn added a comment.Mar 4 2024, 4:48 PM

@Leopard20
Do you think the original issue is caused by that or did you only look at the last comment?

mrzorn removed a subscriber: mrzorn.Mar 4 2024, 7:34 PM
mrzorn added a subscriber: mrzorn.
Leopard20 added a comment.EditedMar 4 2024, 7:55 PM

@Leopard20
Do you think the original issue is caused by that or did you only look at the last comment?

I didn't read your script but all I can say is that you're doing something wrong, and this is not a bug. If you have scripting questions join the Arma discord server, and try the #arma3_scripting channel:
https://discord.com/invite/Arma

Your issue is due to using incorrect data type as the error message says.
You're doing getPos (CVO_Storm_Local_PE_Spawner_array somewhere (I don't know what comes after) and whatever you're passing to getPos is an array

Leopard20 removed Leopard20 as the assignee of this task.Mar 4 2024, 8:02 PM