Bug and Odd Behavior with Arrays

I am fairly new to GP, but have found the combination of customizable widgets and scripting to be perfect for setting up a live guitar rig with my FCB1010 pedal board. However, I have come across some odd behavior with arrays, including what appears to be a bug.

First, the bug: calling a user function that returns an array crashes GP. To confirm this, I created a new rackspace, with no plugins or widgets, and created a very simple script:

var  array1 : double[10]
 
Function GetArray() returns double array
    result = array1
End

Initialization
    var ar : double array
    ar = GetArray()
End

When I compile this script, GP crashes.

The other odd thing I have noticed is that assigning an array to a new variable seems to copy the array, instead of creating a new reference to the array. For example:

Initialization
    var ar1 : double[10]
          ar2 : double array

    ar2 = ar1  //at this point, I expect ar2 to be pointing to ar1, e.g. they are the same array in memory
    ar2[0] = 1.0
    Print("ar1[0] = " + ar1[0])
    Print("ar2[0] = " + ar2[0])
End

Result:
ar1[0] = 0.0
ar2[0] = 1.0

This is unlike any programming language I have ever used. This seriously messed me up for hours trying to debug a script that uses two arrays, one of which gets assigned to a local variable depending on a specific condition. I was setting a member of the local array to a new value, but that value was not getting reflected in the global array that I thought that variable was pointing to. I didn’t see any mention of this behavior in the docs, but maybe I just missed it.

Is there some way to assign an array to a new array variable, such that the variable points to the array instead of getting a copy of it?

I would be confused when ar2 would just point to ar1.

I can reproduce the crash on OS X

Thanks for the replies, PianoPaul.

I would be confused when ar2 would just point to ar1.

Are you saying that you prefer the current behavior, where assigning ar2 to ar1 copies ar1 into ar2? Is this based on another language that you are coming from? There really should be a way to do both.

Tom

GP Script is modeled on the Algol-style (Algol, Pascal, Modula 2) rather than on the C style (C, Java, JavaScript, Lua, etc). In that world, arrays are not pointers.

We will investigate that crash though. Thanks so much for reporting it.

1 Like

I come from Pascal and PL/SQL

2 Likes

Thanks for the quick response, dhj. I can live with the array/pointer behavior now that I know it. It might be good to make that clear in the docs somewhere.

1 Like