Coordinates all wrong on iPhone 3G? It could be yo

2019-01-19 11:27发布

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).

Screenshot of the buggy display

Compare with how this is supposed to look (ignore the difference in colours -- pink is for girls, blue for boys):

Screenshot of a correct display

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?

1条回答
仙女界的扛把子
2楼-- · 2019-01-19 12:08

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:

enter image description here

查看更多
登录 后发表回答