Error with macro and array parameters

Home Forums Problems and solutions in GDL Object design Error with macro and array parameters

Viewing 4 reply threads
  • Author
    Posts
    • #2796
      James Murray
      Participant

      I am getting this error when calling a macro with array parameters:

      ‘Use of uninitialized dynamic array as actual parameter value at line n in 3D script of theMacro.gsm’.

      A placeable object calls theMacro, and passes two array parameters (among other things). The arrays are created by DIM in the object, and are present as 1-column 1-row array parameters in theMacro, so they can be dynamic. Let’s say they are array1 and array2.

      array1 is always used and doesn’t have a problem. Sometimes array2 is not used by theMacro. In that case, I am resetting the array to make sure it doesn’t have old data, then saying

      array2[1] = 1

      …so the array is not completely empty, as this would cause an error. (This is not the error in question.)

      Then the portion of the call looks like

      CALL theMacro PARAMETERS array1 = array1, array2 = array2, etc

      theMacro calls anotherMacro, passing the arrays through with the same kind of call. I suspect the error comes from these calls, where something about array2 isn’t right. If I remove ‘array2 = array2’ from the call the error goes away.

      The portion of anotherMacro that would use array2 is turned off when array2’s data is not present (i.e., array2[1] = 1). So there is no ‘damage’; the object builds correctly overall.

      I can’t be sure where in theMacro the error actually occurs, because the line number reference is not accurate. Usually it is beyond the last actual line number. This would seem to be bug in GDL itself and I haven’t seen it before.

      While the error is not damaging and doesn’t cause a report in the model, I would like to understand it and clear it out. I am confused by 1) the array is in fact initialized, and 2) the array is not empty (array2[1] = 1) when it is passed.

      PS, it would be a very welcome improvement for error dialogs to actually name the variables and parameters they are concerned with.

      James M

    • #2798
      James Murray
      Participant

      This solved it, though I don’t see why:

      DIM junkArray[]
      PUT 0, 0, 15,
      ... x3
      0, 0, -1
      
      FOR k=1 TO NSP
      junkArray[k]=GET(1)
      NEXT k
      
      CALL theMacro PARAMETERS array2=junkArray, etc

      Happy to dismiss the error, but I don’t see why one value in the array wasn’t enough.

      James M

    • #2806
      James Murray
      Participant

      No, I spoke too soon.

      James M

    • #2807
      Dominika Bobály
      Keymaster

      James, could you upload a small example package of the problem?
      I tried to reproduce it:
      – created object with 2 dynamic array variables
      – created macro1 with 2 array parameters
      – created macro2 with same array parameters
      Inicialized array variables in the placeable object, called the macro the same way you did, the macro calls the second macro straight away, same script.
      As long as there was a completely uninicialized array variable, I got the same warning you mentioned (the line number refers to the caller object script, not the macro, so the warning is a bit off in this respect, you are right).
      But the moment all arrays got at least 1 element value, the warning disappeared.
      Not sure if I got your workflow correctly.
      Uploaded my version, to make sure. Please, check.

      Dominika Bobály
      Product Manager
      GRAPHISOFT SE

    • #2814
      James Murray
      Participant

      I found it. I was setting a flag in a subroutine that was leaking out into another routine. But thank you for checking so closely, it motivated me to check more carefully.

      James M

Viewing 4 reply threads
  • The forum ‘Object design’ is closed to new topics and replies.