Hi all
I’m trying to load multiple large images (3600x1800) into a p5 sketch. I can’t use preload because there are over 300 of them and memory issues are crashing the browser. Speed isn’t important though so I’m using callbacks to load and handle them one at once instead like this:
for(var picno=1;picno<=numimages;picno++){
filename="./f"+picno+".png";
loadImage(filename, tempimage => {
image(tempimage,0,0);
tempimage.loadPixels();
processPixelArray(tempimage.pixels);
});
}
function processPixelArray(){
etc
}
The above works except that I need to process the pixel arrays in the order I loaded the images and as the images have different file sizes, the callbacks are coming out of the order that loadImage was called.
I’ve tried variations along the lines of:
var lock=0;
var picno=1;
while(picno<=numimages){
filename="./f"+picno+".png";
if(lock==0){
lock=1;
loadImage(filename, tempimage => {
image(tempimage,0,0);
tempimage.loadPixels();
processPixelArray(tempimage.pixels);
lock=0;
pickno++;
});
}
}
but that locks up the browser as well.
How can I maintain / keep track of the order of these loadImage calls? Is there a way that I can pass in the current value of picno to the callback function (Then read it back in processPixelArray) so that I can track and reorder the data from the callbacks myself?
Thanks as usual for any help…
Simon