setFromPixels & ofThread

Hello, I’m having segmentation fault problems with a threaded function using ofThread. The following lines run without threading, but as soon as I put them into threadedFunction they cause a segmentation fault.

I have basically:

            vector <ofPixels>  myPixels;
            vector <ofImage>   myImages;

    myImages.clear();
    ofImage mycImageTmp;

    for (int i=0; i < myPixels.size(); i++){
            myPixels[i].resize( sizeX , height, OF_INTERPOLATE_NEAREST_NEIGHBOR ); 

            mycImageTmp.setFromPixels( myPixels[ i ] );  // <<<---- **THIS LINE CAUSES SEG FAULT.**

            myImages.push_back( mycImageTmp );

       }

I also noticed that I can’t use emplace_back with a vector <ofPixels> … I don’t know if it could be related to the problem.

any ideas?

data: OF 098
Ubuntu 16.04
using make

@bakercp

1 Like

Anything OpenGL based (in this case the ofTexture in ofImage) has to be performed on the main thread.

threadChannelExample may be worth a look for a workaround

2 Likes

Arturo’s chapter about threads in ofBook covers a lot of different approaches that can be useful, depending on what you want to do, take a look here

https://openframeworks.cc/ofBook/chapters/threads.html

Also, the function setFromPixels in ofImage automatically updates the texture by default, wihchmay the reason for your segfault.

2 Likes

thanks @jvcleave and @drakko

that is exactly the info that I needed!

1 Like