ofxHapPlayer icon indicating copy to clipboard operation
ofxHapPlayer copied to clipboard

Trouble loading vector of ofxHapPlayer objects

Open nightshining opened this issue 9 years ago • 1 comments

Hello, I tried making a vector of ofxHapPlayers just as below:

vector<ofxHapPlayer> player;  //note: this piece was in .h file

 ofDirectory videoDir;
    videoDir.listDir("movies");

    for (int i = 0; i < (int)videoDir.size(); i++){

        ofxHapPlayer tempVideo;
        tempVideo.setup(videoDir.getPath(i));
        cout << "Loading Movie: " << videoDir.getPath(i) << endl;

        player.push_back(tempVideo);
    }


When running this code I would get the following error in my console:

Loading Movie: movies/Organ_Intro_1.mov *Loading Movie: movies/Organ_Intro_3.mov *VidPlayerDebug(8972,0xa0ea11d4) malloc: ** error for object 0x6fda000: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug *(lldb)

I made sure to log out that my paths were correct. I also tried a single ofxHapPlayer to load each video file which I did with total success. I then found a OF forum entry with the following code below. This code seems to work thus far. My understanding of what is happening is limited, but I thought it may be of interest to see what didn't work and what now works to see if there could be a fix in the addon, or if it's something I'm doing incorrectly on my end. Thanks for the help!

 vector<ofPtr<ofxHapPlayer> > player;  // this line of code was included in .h file

 ofDirectory videoDir;
    videoDir.listDir("movies");


    for (int i = 0; i < (int)videoDir.size(); i++){

        ofPtr<ofxHapPlayer> v (new ofxHapPlayer());
        v->loadMovie(videoDir.getPath(i));

        while(!v->isLoaded()) {

            ofSleepMillis(10);
            ofLog() << "sleeping" << endl;

        }

        player.push_back(v);
        player[i]->play();

    }

nightshining avatar Aug 12 '15 15:08 nightshining

Yep, for now you will have to use new (and delete them if you ever remove them from the vector).

ofxHapPlayer lacks copy or assignment operators to manage its associated resources when you copy or assign it (it gets copied when you put it into the vector).

I'll leave this ticket open and fix that at some point... sorry if you wasted time on it.

bangnoise avatar Aug 18 '15 01:08 bangnoise