i’m trying to load a series of images in setup( ) with the following code:
std::vector<ofImage> imgs_;//declared in testApp.h
//in setup( ) of testApp.cpp
imgs_.resize(300);
for(int i=0;i<selectPatternImgs_.size();i++)
{
char name[256];
sprintf(name,"img%d.png",i);
if (!imgs_[i].loadImage(name))
std::cerr<<"Error! fail to load "<<name<<std::endl;
}
each image is 1024*768 with RGBA 8 bit. i need to load 300 images, but when it loads about 90, the app crashes with the error “terminated due to memory error”
is there any way to solve this? i think it should be quite common for an app to deal with hundreds of images and even videos.
btw, i’m running the app on ipad3 with ios7.1, OF0.8.1
but there is still memory error.
what i want to realize is, the user could view different images when they slip a single finger left or right. could anybody suggest other solutions for this task?
By default ofImage loads the pixels onto the graphics card memory. all 300 may not fit into the GPU memory simultaneously. If you must have all images in memory at once, load them into a vector of ofPixels (RAM based) and load those into displayable ofTexture when you need to see them on screen.
In xCode can you check the memory usage, I think you press command+6 then click Memory Usage in the project navigator while your running your app. Do this with 170 images cause you said that did not crash.
each image will be about 3.14 MB. So 458 looks right. The ipad3 only has 1 GB. And each application is only allowed to use 512 MB of ram max. Looks like you maxed out
You have power to burn on an ipad3, you could take all the loading out of the setup and have a streamer of sorts. eg. Have a thread loading a bunch of ofPixels into a fixed size queue (say 30). After you have drawn the first image, pop it out of the queue and delete the ofPixels. The thread then loads/pushes new images into the queue.
There’s a bit of overhead with the constant loading and deleting, but it’s the only way you can play 500+ big images on an ios device.
yes. maybe this is the only way.
btw, i just find a weird thing that, i run the same app on ipad3 and iPad mini2 respectively, but the memory usage is 230M and 430M respectively. don’t know why there is so big difference.