Thread: Code terminate without errors/warning

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    78

    Code terminate without errors/warning

    Good afternoon once again!


    I am yet again digging into another ancient piece of code (see previous threads). I've come across a project, which runs and processes a certain type of images (size 128x128), but not another (size 256x256).

    Since running the code produces no output in Eclipse, it's hard to say what's going wrong.

    The code is available online. You can just import it into Eclipse right away.

    This input works fine:
    Enter the name of the input image: vase001_128.ucf

    Enter light source:
    Sx: 0
    Sy: 0
    Sz: 1

    Enter min and max depth for rescale
    Minimum : -10
    Maximum : 10

    0 sec. 8259 usec.

    Output depth values in ../depthmaps/lros/vase001_128.ucf_001_lros.txt!
    To reproduce the error, type the following:
    Enter the name of the input image: vase256.ucf

    Enter light source:
    Sx: 0
    Sy: 0
    Sz: 1

    Enter min and max depth for rescale
    Minimum : -10
    Maximum : 10

    Does anyone have any idea how to tweak this stuff?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by in_ship View Post
    Does anyone have any idea how to tweak this stuff?
    Run it in the debugger.
    Kurt

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by ZuK View Post
    Run it in the debugger.
    Kurt
    I've done the following in the terminal:

    Code:
    My-MacBook-Air:LRos username$ cc -g -o lros lros.c -lm
    My-MacBook-Air:LRos username$ gdb
    GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "x86_64-apple-darwin".
    (gdb) exec-file lros
    Reading symbols for shared libraries .. done
    (gdb) file lros
    Reading symbols from /Users/username/Documents/workspacec/LRos/lros...Reading symbols from /Users/username/Documents/workspacec/LRos/lros.dSYM/Contents/Resources/DWARF/lros...done.
    done.
    (gdb) break 480
    Breakpoint 1 at 0x1000029cf: file lros.c, line 480.
    (gdb) run
    Starting program: /Users/username/Documents/workspacec/LRos/lros 
    warning: posix_spawn failed, trying execvp, error: 13
    Cannot exec /bin/bash -c  exec /usr/bin/arch -arch x86_64 /Users/username/Documents/workspacec/LRos/lros .
    Program exited with code 0177.
    (gdb)
    I receive the following warning:
    warning: posix_spawn failed, trying execvp, error: 13
    Cannot exec /bin/bash -c exec /usr/bin/arch -arch x86_64 /Users/username/Documents/workspacec/LRos/lros .
    There seems to be some compatibility error with my hardware architecture.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by in_ship View Post
    Reading symbols from /Users/username/Documents/workspacec/LRos/lros...Reading symbols from /Users/username/Documents/workspacec/LRos/lros.dSYM/Contents/Resources/DWARF/lros...done.
    There seem to be two files called lros
    Are you shure that the right one is executed ?
    Kurt

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Try running gdb as root with the sudo command. Error 13 is permission denied.

    Code:
    sudo gdb ./lros
    Also, consider compiling using -ggdb3 in place of -g for more debugging information.

  6. #6
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Thanks, all!!

    So, I entered gdb as root this time.
    Here's the error dump:

    (gdb) run
    Starting program: /Users/username/Documents/workspacec/LRos/lros
    Reading symbols for shared libraries +. done
    Enter the name of the input image: vase256.ucf

    Enter light source:
    Sx: 0
    Sy: 0
    Sz: 1

    Enter min and max depth for rescale
    Minimum : -10
    Maximum : 10

    Program received signal EXC_BAD_ACCESS, Could not access memory.
    Reason: KERN_INVALID_ADDRESS at address: 0x0000000100280000
    0x000000010000183b in Lee_Ros (I=0x100240000, xo=0, yo=0, zo=1) at lros.c:159
    159 Fy= (I[x+(y+1)*size]-I[x+y*size]);
    It seems I'm accessing an address, which is invalid (does not exist, not free, not given access to, etc.).

  7. #7
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    I = (float *)calloc(size*size,sizeof(float));
    Code:
    Fy= (I[x+(y+1)*size]-I[x+y*size]);
    in the loop y goes to 0 to < size
    Out of bounds access.
    Can't tell you what to do don't know about the algo.
    you could try to calloc size*( size + 1 ) floats
    Kurt

  8. #8
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by ZuK View Post
    Code:
    I = (float *)calloc(size*size,sizeof(float));
    Code:
    Fy= (I[x+(y+1)*size]-I[x+y*size]);
    in the loop y goes to 0 to < size
    Out of bounds access.
    Can't tell you what to do don't know about the algo.
    you could try to calloc size*( size + 1 ) floats
    Kurt

    I see - so you're suggesting to allocate enough space to the variable I, right?

    However, I think this is already done in the normalize() function (lines 54 - 64).

    Code:
    /* normalizing the Image */
    Normalize_Image()
    {
    int x,y;
    
    for (x = 0; x < size*size; x++)
      {
        I[x]=(float) (image.image[x]);;
        Z[x]=0;
      }
    }
    I am not exactly familiar with the math of the algo myself. I was planning to dig deeper into the math if the code gave good results.
    Paper is available here

  9. #9
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by in_ship View Post
    However, I think this is already done in the normalize() function (lines 54 - 64).
    No. Normalize just initializes the array I with the values from the image. Doesn't allocate anything.
    The wrong line takes the difference values from two lines. and accesses a line that doesn't exist ( line with index size ).
    When I say that I don't know about the algorithm then I meant that I don't know about the border conditions of that algorithm.
    Could be that it is sufficient to run the loop only to < size-1 or take the difference of zero - the value in the last line. ( this would happen if you calloc size * ( size + 1 ) as I said in the prev. post ) .

    Kurt

  10. #10
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Aha - I see.

    So this is what I tried now:

    Code:
    msize=3;
    inverse_matrix(msize,&det,matrix);
    
    BIo = 0;
    for (y = 0; y < size-1; y++)
    for (x = 0; x < size-1; x++)
          if (I[x+y*size] > BIo)
          BIo = I[x+y*size];
    
    for (y = 0; y < size-1; y++)
    for (x = 0; x < size-1; x++)
    {
    
      Fx= -(I[x+1+y*size]-I[x+y*size]);
      Fy= (I[x+(y+1)*size]-I[x+y*size]);
    
      Ip = I[x+y*size];
    
      Normal(Fx,Fy,x,y,Ip,slant,tilt);
    ....
    And things worked out perfectly!!!!

    Thanks a ton, ZuK!! You made my weekend!
    Last edited by in_ship; 08-11-2012 at 10:55 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1 code warning I need help with...
    By lucidrave in forum C Programming
    Replies: 7
    Last Post: 08-13-2009, 08:53 PM
  2. Code Help. Terminate on 00.
    By Zionstorm in forum C++ Programming
    Replies: 9
    Last Post: 09-16-2008, 06:38 PM
  3. warning C4702: unreachable code
    By cpjust in forum C++ Programming
    Replies: 8
    Last Post: 05-05-2008, 03:24 PM
  4. a site with gcc warning and errors ellaboration exist?
    By kroiz in forum C++ Programming
    Replies: 5
    Last Post: 10-10-2007, 04:05 PM
  5. Confusion : Warning long code
    By mart_man00 in forum C Programming
    Replies: 10
    Last Post: 04-08-2003, 08:07 PM