Array Index out of Bounds

Hello I have noticed this in quite a few of the patterns.

Does this have anything to do with my settings?

Is it a problem?

Weird. Can you send a screen shot of your settings?

H Ben, thanks for the quick reply. Here you go.

if you notice I have a start gap only because this is installed on the electric scooter and to maintain a smooth flow from part to part, I need to input start index gaps.

I did not notice there is another exact thread. My apologies, but after reading that other thread, I was able to figure out the problem.

It is because the pixel count was smaller than the index count.

Now my question would still remain: Will this be a problem? I ask only because of the particulars of my installation.

If you increase the array size or remove the initial offset from index in render, it should still work OK. otherwise some pixels won’t render (where the index exceeds the size of the array). Since you have multiple gaps and don’t need to worry about the wasted array elements, increase the array size by your gap pixels


pixels = array(pixelCount + 20)

You could also edit the Pixels setting to be the last index+1, but it will overwrite when you change any output board settings since it is automatically calculated (without respect for gaps).

sadly on the scooter I will have multiple gaps. Not just one, and each gap is a different size.

If it is NOT a problem, I think my best approach is to start each channel according to the flow of the pattern.

Am I wrong with this assessment?

That works fine, now that I think on it a bit more, just be sure to override the Pixels setting to last index+1. Then you don’t need to edit any pattern code.

Exactly so for examples purposes channel 1 - start index is 0, and has 10 pixels

Then channel 2 - start index at 11 and has 10 pixels

Then channel 3 - start index at 22 and has 10 pixels - so on and so on. This is what you mean?

No, I mean the Pixels setting just above data speed (not in the output board panel). Your last index comes from channel 2, which set to start at 100 with a count of 63. So the last index will be 163. Set Pixels to 164.

Understood! got it!! Thank you very for the help

1 Like

I keep getting the array index out of bounds error, but I’m almost positive that there is no way I’m breaching the array length. Here is the function that does it. It is very intermittent, and the program keeps running without issue after the error. But I do keep getting the issue.


note that the array length is strlength, and the max the index should get is count+pos -1= floor(random(strlength-wlength-2))+wlength-1

I think this may be different than the original posters problem. Are you using the output expander with gaps?

In your code, line 64 checks for pos+count bounds but doesn’t prevent code from continuing. If true and the array is only strlength long, then it will be true on line 66 as well and go out of bounds.

You can check bounds before, save any variables you want to see when this is the case into exported vars and watch them to help debug (before trying to access).

Any runtime error aborts the current render or before render call. The show must go on, so it will keep trying and won’t usually break the animation.

It can also happen in pattern init code, which would mark the pattern as invalid and it won’t try to continue.

1 Like

Looks like putting an explicit size check does solve the problem. I’m still a bit confused as to how It was ever getting above the limit, but oh well.

You can capture the values of some variables to see if you are still curious :slight_smile:

like so:

export var _n, _pos, _wlength

function swaves() {
if (n + pos >= strlength) {
 _n = n; _pos = pos; _wlength = wlength

Then keep an eye on the var watcher.