Coordinates all wrong on iPhone 3G? It could be your compiler

有些话、适合烂在心里 提交于 2019-12-28 06:45:13

问题


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?


回答1:


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:



来源:https://stackoverflow.com/questions/8391307/coordinates-all-wrong-on-iphone-3g-it-could-be-your-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!