Question about array index out of bounds

Hello guys. I am trying to practice a little with this Pattern. Sometimes the lighting is not correct, I was thinking that the problem is for this. V = pixels[index]

How can I resolve this? Thanks

Hi Kalill! Welcome to the forum.

“Array index out of bounds” is a helpful runtime error that means, “I expected there to be size elements in this array when you declared it as = array(size), and therefore I’ll accept between 0 and size-1 inside the pixels[] square brackets, but you tried to access something higher (or lower) than that.”

My guess is that your pixels array isn’t being allocated with the correct amount of memory.

I would expect to see, somewhere outside of the functions (maybe in lines 1-10 which aren’t shown), declaring pixels like this:

pixels = array(pixelCount)

You may have noticed this in the expression docs:

A global called pixelCount is defined based on how many pixels you’ve configured in settings. You can use this in initialization code or in any function.

So pixelCount is set here:

Pixelblaze 2020-03-10 09-12-35
Pixelblaze 2020-03-10 09-12-50

1 Like

Hi @Changchung,
Adding on to @jeff’s info:

Are you using the output expander? Can you double check that the pixel indexes are contiguous?

I think this could happen if either you run out of array memory (lots of pixels), but that would fail to initialize the pattern. Or if using an output expander the pixel indexes don’t match up with the pixel count. The included patterns assume that an array of pixelCount length will have matching indexes, but eg if you have a channel with start index of 100, and length of 100, the indexes will start at 100, already outside of the bounds of the array.

Most patterns would still work fine with arbitrary start indexes, but ones that make arrays for every pixel will get confused.

I should probably add a warning to the config panel if there are gaps or overlapping indexes, come to think of it!

Is that the stock KITT pattern or customized? If custom can you post the code and your settings screen?

Thanks guys, I am using a expander module but I am having the same message with and/or without the expander. I am trying to fix a jump or imperfection that I see in the pattern and play with it

OK, we’re happy to help if you like. Can you post the code? You can copy/paste or download the .epe file and upload it here.

Hi @Changchung,

Check out this thread:

Same issue was caused by gaps in pixel index on an output expander disagreeing with the array indexes. The easy fix is to override Pixels setting to be the last pixel index +1.