Domanda

I have a problem with QThread. I did some calculation in GUI thread and it worked. But now I try to do a calculation in work thread and there is a runtime error.

A have this function.

double **matrix(int nx,int ny, int shift)
{
    int i;
    double **m=(double **)calloc(nx+1, sizeof(double*));
    for (i=0;i<=nx;i++) m[i]=(double *)calloc(ny+1,sizeof(double))+shift;
    return m+shift;
}

And in run() function a want to do this:

double **lop=matrix(1,2,3);

But in this line there is this error: SIGSEGV Segmentation fault. A don't understand, why the error is only in the work thread. Because when run this in GUI thread, it works.

Excuse me please my bad english.

È stato utile?

Soluzione

You can't shift by 3. You must have things aligned to the word boundaries. Words are two bytes so the shift can only be an even number. Perhaphs you want

return m + shift*sizeof(double*);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top