Last assembly function - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Tools & Technology (/forum-10.html)
+--- Thread: Last assembly function (/thread-8339.html)
Last assembly function - Miglu - Nov 21, 2010 05:23 AM
What is the best way to find out EXC_BAD_ACCESS's origin using the debugger? I mean the problem that is in the last assembly language function. http://developer.apple.com/library/mac/#documentation/DeveloperTools/gdb/gdb/gdb_toc.html is a massive document so it is difficult to find relevant information from it. I tried using po $eax but I always get "Value can't be converted to integer".
RE: Last assembly function - zenkimoto - Nov 21, 2010 08:13 AM
The EXC_BAD_ACCESS error occurs when you try to access memory with no reference. What was your latest change? Did you forget to retain a pointer? If you have no idea, you may have to step through your code with the debugger. Are you writing an iPhone app? If not, you could turn on garbage collection as you learn the ins and outs of objective-c.
Check out this link:
Hope this helps!
RE: Last assembly function - Miglu - Nov 21, 2010 08:37 AM
Thanks. I actually have a decent understanding of how to use the debugger. However, I do not know how to get relevant information from the registers.
This particular problem is about Cocos2D's setOpenGLView method:
Quote:#0 0x7fff816202e5 in glEnable
RE: Last assembly function - Miglu - Nov 21, 2010 12:20 PM
I tried using the applicationDidFinishLaunching method from one of Cocos2D's tests, ActionsTest. EXC_BAD_ACCESS occurs in the setOpenGLView method.
I defined glView as a MacGLView, like in ActionsTest.h.
What is the problem?
Even if someone helps me to solve this problem, could I also have an answer to the general question in the first post
RE: Last assembly function - szymczyk - Nov 21, 2010 12:57 PM
Miglu ' Wrote: EXC_BAD_ACCESS occurs in the setOpenGLView method.
The most likely cause of your crash is the variable glView is NULL. Set a breakpoint at the line where you call setOpenGLView and see what the value of glView is.
Accessing null pointers is a common cause of EXC_BAD_ACCESS errors along with accessing released Objective-C objects that zenkimoto mentioned. Use the call stack viewer in the debugger to find the method you called that caused the bad access. I hope that answers the general question in your first post.
RE: Last assembly function - arekkusu - Nov 21, 2010 01:00 PM
A crash in glEnable is probably because you have no current GL context.
For this particular crash, go to CCDirector.m:290 and before the GL call at that line, add:
printf("About to make an OpenGL call on ctx %p\n", CGLGetCurrentContext());
For the general case:
* "info registers" will show all registers.
* "disassemble" will show the asm of the entire current function, so you can see the instructions leading to the bad access.
* "po $eax" doesn't work because "po" prints Obj-C objects. You want "p $eax", or p $rax" for a 64-bit app. Really, "p/x" to print in hex and correlate to the disassembly.
* "help" for more commands in gdb.
RE: Last assembly function - zenkimoto - Nov 22, 2010 02:13 PM
Are you trying to setup a Mac osx project with cocos2d? If so, there is a set of instructions on the cocos2d forum on how to set that up. Check out this link: http://chris-fletcher.com/2010/10/24/howto-create-a-cocos2d-mac-project/
Hope this helps.