简体   繁体   中英

C++ - SIGSEGV doing push_back on a vector<Mat>

I'm developing an Android App and I have this problem in my native code.

These vectors are global.

vector<Mat> listaMatDes;
vector<Mat> listaMatKey;
vector<int> listaCols;
vector<int> listaRows;

I also have this function, in which descriptors and keyPoints contain the addresses of some Mats (using this function getNativeObjAddr()):

void rellenarObjetos(jlong* keyPoints, jlong* descriptors, jint* cols, jint* rows, int length){

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

        listaCols.push_back(cols[i]);
        listaRows.push_back(rows[i]);

        Mat* aux_des=(Mat*)descriptors[i];
        listaMatDes.push_back(aux_des->clone());

        Mat* aux_key=(Mat*)keyPoints[i];
        listaMatKey.push_back(aux_key->clone());
    }

}

I've checked the two auxiliary Mat and they are created well.

I've this error Fatal signal 11 (SIGSEGV) at 0x00000001 (code=1) and it's caused by the line

listaMatDes.push_back(aux_des->clone());

but i don't know why.

Try to separate listaMatDes.push_back(aux_des->clone()); in:

Mat m = aux_des->clone();
listaMatDes.push_back(m);

This way, you can see if the error really is in the push_back, I would say it's probably in the clone.

Programming the whole day makes you crazy (and silly, at least to me), I was passing from java code an array of LOCAL mat addresses (long[] created using the function getNativeObjAddr() which return the address in memory of the mat), so It wasn't going to work...

I solved it by creating a long array as a class field and passing this array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM