Showing results for 
Search instead for 
Did you mean: 

Cluster array fails to initialize consistently

Go to solution

I have a program where I have a cluster array that enters a while loop as a shift register and is then indexed in a for loop to act on each element individually.  To make this work, the cluster array must be initialized prior to the while loop otherwise an array of length zero is indexed, preventing the for loop from executing, and an empty array is sent to the shift register to start the whole mess again.  My problem is that the array does not initialize every time I run the program, leading to this repeating failure I just described.  This issue is particularly troubling because of its inconsistent nature.  To spare you the headache of interpreting my entire code, I have summarized the situation in the attached example.  This example seems to work fine, adding to my frustration.  Is there a fundamental flaw to this design which might become more apparent in a more complex code? 

0 Kudos
Message 1 of 4

No, there's nothing wrong with the logic in your sample code, at least in the array initialization. You might have to upload the actual project that's causing problems. In the problematic version, are you perhaps initializing a local variable instead of an array, and also writing an empty array to that local variable somewhere else in the code?


I'd discourage the use of all the Value property nodes if possible. You could restructure this code to use a simple state machine with to states. Then you could set the mechanical action of the buttons to latch, which would eliminate the need to reset them to false through property nodes.

0 Kudos
Message 2 of 4

Yes, we need to see the actual code. (Also, what's up with all these CPU burner loops??)

0 Kudos
Message 3 of 4
Accepted by topic author Scorpedon

Upon further analysis, I have found my problem.  In my full program I have several arrays that are all indexed at the nested for loop.  While the cluster array attached to a shift register perpetuates the error, a different array suffers from a race condition that initiates the error.  During the first iteration, this array might have length of zero, preventing the for loop from executing and causing the correctly initialized cluster array into the shift register with length of zero.  While troubleshooting, the obvious symptom was the empty cluster array but the cause was elsewhere.  Thanks for your input.

0 Kudos
Message 4 of 4