iPhone : general debugging tips
I been doing iPhone development for 8 months or so and general life is good (exception is openGL lol).
I building a iPhone 3D game and things were going well. It works fine on the simulator (I know not a true test) and it was working fine on the device.
Now it seems to die on the device and point to some very random things. First time it dies (“EXC_BAD_ACCESS”) is the setting of the delegate.
NSString *url = [NSString
stringWithFormat:@"%@GetPlayerPosition.aspx?playerIndex=%@",
self.baseURL, self.deviceID];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
[request setDelegate:self];
So I just remove the code.
The next time it dies is when it tries to access a 开发者_C百科GLFloat array
GLfloat v[] = {center[0] - eye[0], center[1] - eye[1], center[2] - eye[2]};
Again very random and has worked until now. Its like its running out of memory and just fulls over. Does anyone have any idea's? is there a limit to a class size?
Generally I would be able to solve this but I even gone back to a working version and reimplemented some code and its then starts random behavior.
I checked for leaks and I am fine
UPDATE: Part 2
Right in my interface in my .h file I have
GLfloat eye[3];
In my .m, I can assign a value to each element and it works fine
If I do
NSLog(@"%f",eye[0]);
It crashes. Why is this? (used to work)
If there is a crash (or crashes), there will be backtraces. Post them.
Try "build and analyze". Fix any warnings it gives you. Fix any warnings the compiler gives you, too. A properly written app should compile without warnings.
why the
__block
on that line of code? There doesn't seem to be anything blocks related there.
Nothing ever randomly breaks when writing software. If something starts crashing with a seemingly unrelated change, it is likely that the code was always broken, but wasn't causing a fatal problem until the later change.
Since you aren't writing to request
, there is no reason to mark that variable as __block
. Since __block
will cause request
to not be retained, it might be that the object is being prematurely released & deallocated. Maybe.
How are you allocating the float arrays?
How are center and eye declared? Are they instance variables, globals or static variables? It could be somehow the memory for those arrays has been released by the time the callback occurs (which would also explain why the line initializing the float array fails).
EXC_BAD_ACCESS is often the symptom of premature deallocation (e.g. trying to access a deallocated object because it was released too many times).
it was working fine [...] Now it seems to die
Sounds like you should look through your revision logs to see what changed between those two timestamps.
精彩评论