I am getting a "EXC_BAD_ACCESS" message when I try to allocate memory for a two dimensional array. While changing my code around to figure out what was going on, I was getting some inconsistent effects (code works fine, then doesn't next time it is run). I get the error for the following, which is contained in a method that is called from another class:
This is the debugger output:
Any ideas what is going on? As I mentioned, results were inconsistent. Another example: this same section of code worked fine at least once when I had variables in place of 300 and 400.
Code:
float **floatArray;
//breakpoint 1
floatArray = malloc(400*sizeof(float*));
for(int i = 0 ; i < 400 ; i++){
//breakpoint 2
floatArray[i] = malloc(300*sizeof(float));
}
//breakpoint 3
This is the debugger output:
Code:
(gdb) continue
Current language: auto; currently objective-c
(gdb) continue
Program received signal: EXC_BAD_ACCESS.
(gdb)
Any ideas what is going on? As I mentioned, results were inconsistent. Another example: this same section of code worked fine at least once when I had variables in place of 300 and 400.