简体   繁体   中英

Thread 1 : EXC_BAD_ACCESS in Xcode with C code

I am using Xcode to code in C language. I am getting strange error.

If ranges( height2, width2 ) of for loops are around 500,600 code is working fine. BUT if I change ranges more than 800 then it gives me following error.

"Thread 1: EXE_BAD_ACCESS(CODE - 2, address = 07x33434...)"

for (int i = 0 ; i <height2 ; i++)
{
    for (int j = 0 ; j< width2 ; j++)
    {
        float height_Frac_Idx = i*scale_h;
        float width_Frac_Idx = j*scale_w;
        int height_idx, width_idx;
        height_idx = (int) height_Frac_Idx;
        width_idx =  (int) width_Frac_Idx;
        float del_h = height_Frac_Idx - height_idx;
        float del_w = width_Frac_Idx - width_idx;


        img_op[i][j] = (img_IP[height_idx][width_idx])*(1 - del_h)*(1-del_w) + (img_IP[height_idx+1][width_idx])*(del_h)*(1-del_w) + (img_IP[height_idx][width_idx+1])*(1 - del_h)*(del_w) + (img_IP[height_idx+1][width_idx+1])*(del_h)*(del_w);            

    }
}

"Thread 1: EXE_BAD_ACCESS(CODE - 2, address = 07x33434...)"

This error come when when you accessing the unallocated or more that allocated memory in code.

Looking your code and explanation i can guess that you probably accessing some more memory in case of img_op[][] or img_IP[][] array.

Also try Enabling NSZombies Very easy to enable:

  1. Double click your executable in the “Executables” in XCode

  2. Open “Arguments” tab

  3. In “Variables to be set in the environment” (that's the list at the bottom, be careful which one you edit) click the “+” button and for name of the variable enter “NSZombieEnabled” and for value “YES”

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