Sign in to follow this  

Reference problem ?

Recommended Posts

LDenninger    122
Ola Andreas, I've got a little problem :) I have registered a structure 'GridParameters'. I have a function declared as : "void Draw2DGrid(GridParameters &inout, string &in)". The second 'in'-parameter is the name of a scriptfunction. In my script I have a global : "GridParameters grid_parameters". I call the function like this : "Draw2DGrid(grid_parameters, "PerPixelFunction")". the Draw2DGrid-function looks up the PerPixelFunction and executes it. The PerPixelFunction in the script modifies the global 'grid_parameters'. Or at least - it should :) the problem is - if I change anything in the grid-parameters from my main function and call Draw2DGrid, the values are actually modified - like it should. But whatever the "PerPixelFunction" does - the 'grid_parameters' doesn't change ! Imho everything should work fine, since it all works with a reference to the same global 'grid_parameters'. (The Draw2DGrid gets a reference to the global, and the PerPixelFunction uses the global). Any ideas ? Edit: hmmmm, after re-reading this it might not be so clear :) the script : <snip> GridParameters grid_parameters; void PerPixelModification(float inX, float inY, float inDistance, float inAngle) { grid_parameters.RedDecay = 10.0f; grid_parameters.GreenDecay = 10.0f; grid_parameters.BlueDecay = 10.0f; grid_parameters.Rotation = -0.053 * 9.0f; } void Draw() { grid_parameters.RedDecay = 2.0f; grid_parameters.GreenDecay = 2.0f; grid_parameters.BlueDecay = 2.0f; grid_parameters.Rotation = 0.0f; Draw2DGrid(grid_parameters, "PerPixelModification"); } </snip> The Draw2DGrid function (cpp) : - get the function-id of "PerPixelModification" - execute it. after execution, the members of the structure passed in the 1st param of Draw2DGrid are still set to the values assigned in the 'Draw'-funtion. :( [Edited by - LDenninger on November 23, 2005 6:57:52 PM]

Share this post

Link to post
Share on other sites
WitchLord    4678
You've come upon one of the major problems with parameter references in AngelScript. I desperately need to find a solution to this, that is still secure and safe (as in sandbox), and still allows you to do what you normally want to do with references.

The problem is that the reference that Draw2DGrid() receives when called from the script is not a reference to the true grid_parameters variables, but instead a copy of it. Any changes made to this parameter are only reflected on the true grid_parameters when the Draw2DGrid() function returns, as the script then copies the clone back to the original grid_parameters.

This solution was chosen in order to guarantee that the parameter reference is always valid, even if the original grid_parameters variable is somehow destroyed during the execution of Draw2DGrid().

For AngelScript 2.5.0 I'm planning on removing parameter references as they are known now. Only output references will still be available as they are the ones that truly works without any confusion. This will limit the language, but at least it will not cause confusions anymore.

If I can find a safe solution to parameter references that doesn't cause confusion in the future I will reimplement them. In the meantime I recommend using object handles instead of parameter references.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this