Tuesday, July 5, 2011

WWDC 2011@SF, with Kato~~

It's my first trip to USA, and it was fantastic!

WWDC 2011's ticket was sold out within 10 hours! and over 5200 attendees from all around the world. And also, Apple announced iCloud, iOS5 and Lion, the next generation of Mac OSX. Besides a lot of technology sessions presented by Apple's engineers, there were also pretty much useful Labs for anyone have some problems on his code. They can ask Apple's engineer directly. Maybe they can meet some guy inside the team which is responsible for the problem. I met one in the UIKit team, and answered a lot of my questions. It's really helpful.

Hope to enjoy WWDC 2012, and hope to be able to USA more freely.

Monday, July 4, 2011

What cause EXC_BAD_ACCESS and other EXC_BAD_XXX errors happen?

EXC_BAD_ACCESS and some similar errors are common to iOS developer. You never met one? Oh, god, you are the god, u don't need to read this post.

I, Tonny, as an extremely normal iOS programmer, EXC_BAD_XXX error is the most familiar error I meet everyday. But WHAT the hell cause these boring error messages? I don't want to dig too much deep, I just want to know what's the most likely reason cause each non-human readable error.

The lucky thing is Apple explained some of them many years ago, the unlucky thing is without search engine, you won't be able to find this document. And what's the most lucky thing is we have google(bing can also find this document). It can help a little.
  • EXC_BAD_ACCESS/KERN_INVALID_ADDRESS — This is caused by the thread accessing unmapped memory. It may be triggered by either a data access or an instruction fetch; the Thread State section describes how to tell the difference.
  • EXC_BAD_ACCESS/KERN_PROTECTION_FAILURE — This is caused by the thread trying to write to read-only memory. This is always caused by a data access.
  • EXC_BAD_INSTRUCTION — This is caused by the thread executing an illegal instruction.
  • EXC_ARITHMETIC/EXC_I386_DIV — This is caused by the thread doing an integer divide by zero on an Intel-based computer. 
  • Source:http://developer.apple.com/library/mac/#technotes/tn2004/tn2123.html
You see? This tech note was published in 2004! that's 7 years ago on the very beginning that Apple started to ship Mac with Intel inside.  Why I say "very beginning", because Apple publicly announced it would ship new Mac with Intel's CPU on 2005[Source:Wiki].

And also, EXC_BAD_ACCESS has 2 meanings! Usually on iOS device, EXC_BAD_ACCESS is caused by accessing released object, but obviously, it has much more meanings than we expected.

Hope I can update this post later for more detailed information about any EXC_BAD_XXX error message.