Image preloading limit?


I’m trying to load 100 (1024x768) jpeg images into an array and then display them one after another.
For some reason it loads only first 20 images and the rest 80 are blank. It looks like it’s a memory
issue, because when I reduce their size (from 1024x768 to 50x50 for example) I can load all 100.

But where this limit comes from ? One jpg is about 24 kilobytes. So 100 images would make it
24MB. Not that much it seems.


Each ofImage creates an ofTexture that takes up GPU memory. This is the limit you are probably running into.

You can disable the texture and reenable it when you need to draw it

a jpg make 24kb when it is stocked, because it uses compression, but when you display it, it uncompress itself, at one point or another.

as @cgiles says jpegs needs to be uncompressed so at 1024x768x3=2.25Mb per image for 100 images that would be 225Mb. For a desktop computer that shouldn’t be a problem and even passing the limit of available video memory it would store images in RAM and swap whenever those textures need to be shown.

since you are posting on arm i get you are using a raspberry pi or similar? in that case check how you are dividing the memory usage between ram and video.

also what @jvcleave proposes kind of works but has a problem since once the texture is loaded for the first time it’ll stay in gpu memory anyway so disabling it doesn’t have much effect.

one possibility would be to load the images using ofLoadImage(path, pixels) where pixels are ofPixels object so the images get loaded to pixesl in ram then whenever you want to show one of the images use only 1 ofTexture and load the pixels into it using texture.loadData(pixels)


Thanks for detailed answer!
Ah, so jpeg needs to uncompressed. Ok. But could this be a reason why only 20 load ?
I will check memory repartion as well.