Vector.push_back(ofImage()) can't allocate region in 32-bit compile

Hello all,

I’m using the latest nightly build to load a vector of ~9000 images. In of_v0.9.3 my vector does not have a problem allocating, but unfortunately this nightly build is the only build that will run ofxThreadedVideo, an addon I’m definitely going to use.

The allocation stops at 4096 images. In the of_v0.9.3 you can see it hiccup at 4096, but then continue.


Now, if you want to talk about why this nightly build is the only one that will allow me to use ofxThreadedVideo, then we’ll talk about that too, but this alloction error seems like a more pressing issue because the nightly build has been changed for the better to allow ofxThreadedVideo to work. But, the vector.push_back(ofImage()) allocation error is something that has broken in the nightly (I’ve tried all this on of_v0.9.4 - the vector.push_back(ofImage()) works, but the ofxThreadedVideo still does not)

I’ll upload my current code to my github (in the tSNE one, but it’s not updated yet) in a couple hours.

Cheers,

nick

Alright, just tested my code on the newest nightly build of_v20160504_osx_release and no more allocation errors!

Cool. (psst @bakercp look! fixt!)

SIGABRT refers to an abort() function which is usually called in the case of allocation errors… as does the malloc.

I suggest you try this in the for() loop in the first screenshot.

ofImage im;
im.load(filePath);
images.push_back(im);

1 Like

Aha, it actually isn’t working in the newest nightly 20160504 and I think it is because I have to compile in 32-bit for ofxThreadedVideo because of some Quicktime issue (look at the readme).

So it seems that xcode debug 32-bit mode has the allocation issues.

I’ve updated my github code. The media imageSequences that goes into bin/data and put it as a separate download here.

@bakercp false alarm, still not working.

Hey @kashim thanks for the reply, but that did not work.

For each ofImage a texture is going to be created. You may be running out of GPU memory

I would see if this helps

ofImage im;
im.setUseTexture(false);
im.load(filePath);
images.push_back(im);
1 Like

@jvcleave The vector loads all 9000+ images when ran in a 64-bit compile, so it probably isn’t that I’m running out of GPU memory.

I’ll try your fix idea right now.

@jvcleave your idea of adding im.setUseTexture(false) did allow the app to “load” the images in the 32-bit compile, but the images did not draw because of the that, and I definitely need those images to be drawn.

You can turn on setUseTexture(true) on/off before/after you draw them. (You may have to call ofImage::update)

In a similar way you could use ofPixels instead of ofImage and use texture.loadData(pixels) when you need to draw them.

1 Like

@jvcleave Aha!

This seems to do the trick:

void ofApp::setup(){
...
    ofLog() << "Gathering images...";
    ofDirectory dir;
    int nFiles = dir.listDir(ofToDataPath("imageSequences/"));
    if(nFiles) {
        for(int i=0; i<dir.size(); i++) {
            if (i % 20 == 0)    ofLog() << " - loading image "<<i<<" / "<<dir.size();
            string filePath = dir.getPath(i);
            ofImage im;
            im.setUseTexture(false);
            im.load(filePath);
            images.push_back(im);
            //images.push_back(ofImage()); // having allocation issues with 32-bit
            images.back().load(filePath);
            filenames.push_back(dir.getFile(i).getFileName());
        }
    }

    for (int i = 0; i < images.size(); i++){
        images[i].setUseTexture(true);
    } 
...
}

After they load, I put this for() loop to turn the textures back on, and it drew the images!

Thanks Jason!
Also thanks @kashim for contributing to the solution.

1 Like

By the way, @genekogan this vector.push_back(ofImage()) code is originally from your ofxTSNE/example-images/src/ofApp.cpp, just in case this issue pops up again.