freeze screen when DIR.listDir loop

Hello

I’m a beginner in C++, but when i see the possibility of Of I enjoy to use it.
And in a first time thank you for your work on OF !!!:smiley:

Now in a script i user a function to do a DIR.list when a video is playing.
I have a probleme because the screen freeze as long as the function of DIR.list execute.

Do you have an idea for this problem ? :roll:

  
   
  
void testApp::reloadS(){  
  
  
    DIR.setVerbose(false);  
    nImages = DIR.listDir(repMedia);  
    videosTemp  = new ofVideoPlayer [nImages];  
    imagesTemp  = new ofImage       [nImages];  
    nbrVideo=nImages;  
  
    //you can now iterate through the files as you like  
    for(int i = 0; i < nbrVideo; i++){  
           // fichier = DIR.getPath(i);  
            const char * fichierName = DIR.getPath(i).c_str();  
            char       * ext;  
            ext        = strstr(fichierName,".");  
  
  
            if (strcmp (ext,".mov") ){  
  
                videosTemp[i].loadMovie(DIR.getPath(i));  
                videosTemp[i].play();  
  
            } else if (strcmp (ext,".jpg") == 0){  
  
                imagesTemp[i].loadImage(DIR.getPath(i));  
  
            }else {  
                cout <<"INDETERMINE"<<  ext << endl;  
            }  
  
            //  
  
  
            //  images[i].loadImage(DIR.getPath(i));  
    }  
  
    currentImage = 0;  
  
}  
  
void testApp::draw(){  
	ofSetColor(0xFFFFFF);  
  
      
    if (timerMaj==0){  
  
        if (ofGetSeconds()>40){  
            timerMaj = 20;  
        }else{  
            timerMaj = ofGetSeconds()+20;  
        }  
  
    } else if (ofGetSeconds()==timerMaj){  
        reloadS();  
        timerMaj =0;  
    }  
  
// and other things put on the screen video and pitcures  
// the problem is the video witch are on the screen are freeze the time of  execution of reloadS();  
  
  
}  
  
  

Do you have an idea ?

Can I find a solution

Thank you for your reply

after read the forum this nigth, i think I must create a thread by operation.
so i will try to o that

Hi cybunk, I´ve got an eye on this discussion, because I´m having the same freeze up here. I´m also looking towards the possible thread solution.

[quote author=“cybunk”]Hello
Do you have an idea for this problem ? :roll:
[/quote]

i think your problem is with loading the images, not listing the directory.

try loading all the images at the start of the program (ie in setup()) and store them in a vector or an array, instead of dynamically loading them. it’s best to avoid threading if you can, especially if you’re a newbie :slight_smile:

Hi Damian,
on my case, my app should load batches of 45 movies at a time.
If I do load hundreds of Quicktime movies on a array at startup, could that sacrifice performance during the app running time? (The setup part would “freeze”, but that´s much more acceptable).
Thank you for the tip, I shall test that right now.

@damian :
Yes it’s probably it’s not the listing, but the loading… :wink:

@alexander :
for the solution my inspiration come from this post :
http://www.openframeworks.cc/forum/view-…-ght=freeze

cybunk,

can I please see how you got the thread for the listing/loading running?

[quote author=“AlexandreRangel”]Hi Damian,
on my case, my app should load batches of 45 movies at a time.
If I do load hundreds of Quicktime movies on a array at startup, could that sacrifice performance during the app running time? (The setup part would “freeze”, but that´s much more acceptable).[/quote]

no, it won’t; it will only affect how much memory your application is using. if you don’t call idleMovie() (or is it update() you call? i forgot) on a movie, it won’t be using any CPU.

you have the mighty power of openFrameworks. as a long time C++ programmer i’m amazed at what newbies are doing with C++. many cheers for Zach and Theo and Arturo :slight_smile:

Yes, without Of i never can do that !

Thank you and cheers Zach and Theo and Arturo :slight_smile:

Thanks Damian, it works like a charm. No hickups at all, now!

I have an other question about ofdirlist.

can we use it to list a network directory (in windows) ?

[quote author=“cybunk”]I have an other question about ofdirlist.

can we use it to list a network directory (in windows) ?[/quote]

if you can mount to network directory onto a drive letter (eg Z:) then yes, definitely.