Thread: Error going in a function

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    33

    Error going in a function

    Hi I have no error compiling, but running my project it stops before entering a function and debugging I have an error about Segmentation fault. The function:

    Code:
    1 2 3 4 5 6 7
    Mat logGabor(matriz filter,Mat filter,double r_o,double theta_o,double sigma_theta, matriz radius,matriz theta,int cols,int rows,double sigma_r,int *padSize){ Mat rpad; int k=*padSize; printf("Welcome to the function"); //Here the error ...
    More info: I created the matriz as : typedef double** matriz;
    and a createmat function that give back a double** and in this function I allocate space for matriz and works. In the main:

    Code:
    1 2 3 4 5
    Mat chr-Rpad[4][5]; //chrOrient=4;chrScales=5 for(int i_or=1;i_or<chrOrient;i_or++){ for(int i_sc=1;i_sc<chrScales;i_sc++){ //some math calculation chrRpad[i_or-1][i_sc-1]=abs(logGabor(filter,imftt2,r_o,theta_o,sigma_theta,radius,theta,cols,rows,sigma_r,padSize));
    Last edited by Elvio Esposito; 07-02-2013 at 07:29 AM.

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    32
    If you have, for example
    Code:
    int padSize;
    call function as:
    Code:
    logGabor(filter,imftt2,r_o,theta_o,
                   sigma_theta,radius,theta,
                   cols,rows,sigma_r, &padSize)

  3. #3
    Registered User
    Join Date
    Jun 2013
    Posts
    33
    I have :

    Code:
    int*padSize;
    
    padSize=(int*)malloc(sizeof(int));
    invoking with & operator is an error.I assign a value to the padSize in another function.And I use malloc to conserve it.
    Last edited by Elvio Esposito; 07-02-2013 at 08:43 AM.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Can you post your code? Or if it's too big, can you post a simplified version that exhibits the same behaviour?
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Jun 2013
    Posts
    33
    I post something more. All the project now is around 500 lines and they compile. Don t gonna post the function when I can t enter and how I call it in main. It s above how it starts. That s a function give me before a lot of problem because (see insider comments):

    Code:
    void pre_filter_Computations(matriz radius,matriz theta,int cols,int rows){
    
      double X[rows][cols],Y[rows][cols];
      double x[cols],y[rows];
      double epsilon = 0.0001;
    
      for(int i=0;i<cols;i++){
          x[i]=((double)(i-cols)/2)/((double)cols/2);
      }
    
    
      for(int z=0;z<rows;z++){
           y[z]=-(((double)(z-rows)/2)/((double)rows/2));
       }
    
    //MESHGRID
    for(int m=0;m<rows;m++){     //I putted cols before for the meshgrid
      for(int n=0;n<cols;n++){   // I used rows before the meshgrid
           X[m][n]=x[m];
           Y[m][n]=y[n];
      }
    }
    
          for(int a=0;a<rows;a++){
                for(int b=0;b<cols;b++){
    
                     X[a][b] = pow(X[a][b],2);
                     Y[a][b] = pow(Y[a][b],2);
                     X[a][b] = X[a][b] + Y[a][b];
                      radius[a][b] = sqrt(X[a][b]);
    
              }
          }
    
        radius[rows/2+1][cols/2+1]=1;
    
          for(int a=0;a<rows;a++){
               for(int b=0;b<cols;b++){
                   radius [a][b]= radius[a][b] + epsilon;
                   theta[a][b] = atan2(Y[a][b],X[a][b])*180/PI;
               }
          }
    }
    
    Whit meshgrid I mean:
    Code:
    [X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables and three-dimensional mesh/surface plots. The rows of the output array X are copies of the vector x; columns of the output array Y are copies of the vector y.
    
    As for my teacher's info I have to pass to x vector the cols and to y the rows (as I do at the start of that function) I putted before cols in the meshgrid innested for. And so printing the rows and cols after the meshgrid, they were too much. But now maybe I have an error at meshgrid calculation. I m not sure it work as I said in the explication. That' s important because it create after the radius I pass to the function I can not enter. MAybe the error is there.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Closed for cross-post madness and crappy unreadable code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2012, 02:37 PM
  2. Error "in function 'main' syntax error before 'int' Help Please
    By blackhat11907 in forum C Programming
    Replies: 5
    Last Post: 08-20-2011, 07:05 PM
  3. Replies: 8
    Last Post: 07-08-2011, 01:16 PM
  4. Error: _ defined as a function returning a function?
    By Jardon in forum C Programming
    Replies: 15
    Last Post: 07-29-2009, 11:53 AM
  5. function calling within another function error
    By bazzano in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 01:40 AM