I seem to be running up against a memory limitation of some sort while working with bitmap animations packed into literal arrays. I am using this python script that Pixie posted to generate the Pixelblaze code for my image arrays. My images are 32 pixels by 23 pixels, and so far I have only been able to successfully load/preview/run a 3-frame animation (3 frames of a 32x23 bitmap). It runs well and looks great!
However as soon as I paste the additional code into the editor with the array for the 4th frame, the editor freezes up. I’ve tried over 20 times now, power cycling the PB and deleting the previous pattern attempt from memory in between each try. Generally it freezes while trying to generate the preview, and so it never previews or runs or gives me a chance to hit the Save button (and then I have to power cycle to unfreeze the editor). Occasionally it will allow me to try to hit the Save button after adding the the full 4 frame code, but then it will throw an error in the middle of the save process. I have however once or twice managed to get it to save the code for all 4 frames, but as soon as I try to activate the pattern it then freezes while trying to run/preview it. So I get various behaviors from the UI, but the end result is the same in all cases: it cannot run the full 4-frame code. The 3-frame code works perfectly however, and the only difference between the two is addition of the extra arrays holding the 4th frame of the bitmap. So I’m guessing somewhere between frame 3 and frame 4 I am hitting a memory limitation? How would one analyze/determine that? (As an aside, my pattern list page says I have 600K free, and the text for this code is only 166K. So to me that suggests I’m not dealing with a storage issue, but rather hitting a memory limitation when the code is being executed.)
Here is a Pastebin link to the full 4-frame code (was too big to paste as a code snippet): https://pastebin.com/rZ2PNqL4
Reporting some progress on this. It seems I was dealing with multiple issues, one of which being the overhead of several thousand calls to packRGBA and putPixel (the pixel and image helper functions). When I remove these helpers and simply declare my pixel data as arrays of raw hex, the PB interface behaves much better. I am now able to easily preview/run/save an animation as large as 9 frames of a 23x23 bitmap, so 4761 pixels. Because I am now storing my RGBA data as 16-bit pairs, that’s 9522 pixel array elements. So while this is not as efficient of a way to pack pixel data into arrays, the PB UI handles it far better than it handled thousands of calls to the helper functions doing the packing/unpacking.
With this method, I am now hitting a different limit, one which may actually be the array memory limitation I have seen discussed in other posts. When I try to add in a 10th frame to my animation, I now get a very specific “Array index out of bounds” error that highlights row #6 in of pixel data of the 10th frame…which would be somewhere in the neigborhood 9750 pixel array elements. If you count the elements of the 3D array structure as well (frames, rows) it’s more like 9990. Fortunately the UI is not freezing up or acting poorly in any way when I encounter this limit, it’s simply refusing to run the pattern with the 10th frame added in, and correctly resumes running the pattern after I remove the offending extra frame’s arrays. That’s a vast improvement over where I was getting stuck with the previous method using helper functions after adding only 4 frames.
I suppose my questions now are:
Am I analyzing this correctly, and have I now reached the true practical limitations of the PB for animating bitmap data in arrays?
Is the limit I am now hitting solely based on the number of array elements, or something else?
Is there a way to more effectively pack my pixel data into arrays that would allow me more data with the same number of array elements? (One that doesn’t require a helper function like packRGBA, as that apparently won’t scale well with thousands of calls crashing the UI.)
Yes, as you have guessed you are hitting memory limits.
My guess is that originally your code was running the chip out of memory and crashing. There’s a fairly high but finite limit to how many operations can be in a pattern and still fit in the microcontroller.
For arrays, this is more well defined. You have about 10k elements. The free array memory can be seen in the status area on the top right of the page, near FPS.