ofDirList pass ofImage freeze

Hi everyone,

I am trying to display a lot of image, but in some point my app freeze, i did a class using ofDirList

//header

int nImgDir;
ofImage * images;
ofxDirList DIR;

//---------------------------

//cpp

ofSetLogLevel(OF_LOG_VERBOSE);
//DIR.setVerbose(false);
nImgDir = DIR.listDir(“images/A”);
images = new ofImage[nImgDir];
for(int i = 0; i < nImgDir; i++){
images[i].loadImage(DIR.getPath(i));
}

//after that i designed other class to draw i called structureA

//------------------------------------
//header

void setupDir(ofImage& imgDir);

ofImage imgDir;

//cpp

void structureA::setupDir(ofImage& _imgDir){

imgDir= _imgDir;

}

void structureA::draw(){
ofSetColor(255, 255, 255);
imgDir.draw(x, y, w, h);

}

//------------------------------------

//finally in the testApp i put this code

//header

#define nElements 9

class testApp : public ofSimpleApp{

public:
vector <estructuraA *> vElement;//i am using a vector pointer

baseData baseDataA;

}

//cpp

for (int i = 0; i < nElements; i++){
estructuraA * a = new estructuraA();
vElement.push_back(a);
vElement[i]->setInitialCondition(0.0, 0.0, 0.0, 0.0, 320, 240);
vElement[i]->setup(320,240);
ofImage& imgDir = baseDataA.images[i];
vElement[i]->setupImg(imgDir);
}

Thank you for your reply

hi,

it’s difficult to help you without some more information.

if you press the ‘pause’ button on your debugger, you should be able to break into the application to see which line it’s frozen on.

or maybe, it’s not freezing, it’s just running out of images (IIRC ofxDirList only returns the first 100 entries in a directory.)

you can also try putting in lots of printf() statements so you can see where it’s freezing, exactly.

hth,
d

Hi,

I checked the points you said damian and it wasnt that, i am only using 9 image per directory, i need like a hundred directories , in the debugger didnt say anything i thing the problem is that the memory of my computer could not run so many images.

How can i optimaze the process? do i use pointers? and in that case, how can i pass the image through the classes?, or maybe, is it necessary try with an other method?.

Thank for your reply

hi,

i doubt the memory will be your problem. how many images are you loading? you should be able to load several hundred images without a problem, but if you’re loading more than this, or if it’s your entire operating system that’s freezing, rather than just your application, then you could be right.

you need to describe more in detail what kind of freeze you’re getting, what OS you’re on, exactly what is happening.

also, please put in a bunch of printf statements into your code like i suggested, so that you can know for certain where the problem is.

d

Hi,

i did what you say and I discovered that myApp run after all but it took to much time to do it that i believed that it was freezing, i change the structure follow the advice of other topic in this forum, i am trying to delete the diinamic memory but i thing is not working,

//header class baseImgs
//-----------------------------------

class baseImgs
{
public:
baseImgs();
virtual ~baseImgs();

ofImage* images[9];
void setup();
void exit();

}

//cpp class baseImgs
//-------------------------------------------------------
baseImgs::baseImgs(){

}

void baseImgs::setup(){

for (int i = 0; i < 9; i++){

images[i] = new ofImage();
images[i]->loadImage(“default/images/0” + ofToString(i+1)+".jpg");
}
}

void baseImgs::exit(){

for(int i=0; i < 9; i++){
delete images[i];
}
}

baseImgs::~baseImgs(){
//destructor
}

//header class structureA
//-------------------------------------------
class estructuraA
{
public:

ofImage* imagenE;
void setUpImg(ofImage* imagenE);
void draw();

}

//----------------------------------------------------
//cpp class structureA

void structureA::setUpImg(ofImage* _imagenE){

imagenE=_imagenE;

}

void estructuraA::draw(){

imagenE->draw(x, y,w,h);
}

//------------------------------
//header testApp
vector <structureA *> vector;
baseImgs baseDeImgs;

void exit();

//------------------------------
//cpp testApp

void testApp::setup(){
baseDeImgs.setup();
}

for (int i = 0; i < 9; i++){
structureA * a = new structureA();
vector.push_back(a);
ofImage* imagenE=baseDeImgs.images[i];
vector[i]->setUpImg(imagenE);

}

void testApp::exit(){
//for(int i=0; i < nAmerica; i++){
//delete this->iAmerica[i];
//}
baseDeImgs.exit();
printf(“is myApp working?”);
}

//My App run but it takes to much time to begin and the whole system works very slow, how could i fix this problem?