Note: This is question to which I have already found an answer. It seems that posting a question after finding an interesting answer is encouraged, so I am posting this. Someone else is likely to have the same problem and find this useful.
I have an iOS app that produces charts. Shortly after publishing an update, a user sent me this panicky email:
"the latest update has modified the curves ... not seen more growth curves and inserted data are represented as a line descending ... before you could see perfectly well
Help me"
I get him to send a screenshot and give more detail. He has an iPhone 3G and this is how girl's chart looks. Most points are drawn at the wrong coordinates: they appear to be drawn at (x,x) instead of (x,y).
Compare with how this is supposed to look (ignore the difference in colours -- pink is for girls, blue for boys):
After much experimentation, I send him a rebuilt version of the previous version (which worked OK for him) and it still doesn't work. So in the end it appears that the code changes in the update have nothing to do with it. What could be the explanation?
iPhone original and iPhone 3G use the armv6 architecture, later models armv7. An answer to this Stack Overflow question, and an Apple developer forum thread point to a problem in the armv6 Thumb code produced by XCode 4.2's compiler which cause arithmetic operations on certain data structures, in particular
CGPoint
, to return completely wrong results. Such as the x value being written into the y value.The solution is to add the
-mno-thumb
compiler option to the XCode project. This tells the compiler not to emit Thumb mode code, thereby bypassing the bug. Another solution is to switch back to an earlier XCode (pre-iOS5 SDK), which doesn't have this bug.So the bug is in the compiler! How cool is that? :) In two decades of developing, I was yet to come across such a thing.
Here's a screenshot showing where to add this compiler option if it helps anyone: