obj_msgSend function pointer crash when build with 64bit arm64

橙三吉。 提交于 2019-12-04 13:08:01

问题


Actually my original code works great with Xcode 5.0.2 and also great for sending to App Store which is:

objc_msgSend(self.target, self.successAction, category);

This line causes crashes with Xcode5.1 beta5. I found a solution to fix the crash: SudzC ARC version - objc_msgSend call causes EXC_BAD_ACCESS using 64-bit architecture

// solution
id (*response)(id, SEL, id) = (id (*)(id, SEL, id)) objc_msgSend;
response(self.target, self.successAction, category);

And I get no problem at all either using Xcode 5 or Xcode5.1beta to test on devices(iPhone 5s) or simulator(32bit or 64bit) when using the recommended solution. The architectures setting in Build Settings is "Standard architectures (armv7, armv7s)" in Xcode 5 and "Standard architectures (armv7, armv7s, arm64)".

However, my new version of app is ready for sale on App Store today. And it crashes on every devices(iPhone 5s, 5, 4s) installed (according to Crashlytics report). Since I don't get the crash using Xcode(build to real device), I don't know if I fix the problem or not before reviewed by Apple.


回答1:


Finally, I can reproduce the crash right now. Simply edit Build Scheme and change "Run YOURAPPNAME.app" from Debug to Release.

And right after I can reproduce this bug, I know how to fix it. Since my selector function type is void(does not return anything), I should not just copy what the question does (using "id").

By changing:

id (*response)(id, SEL, id) = (id (*)(id, SEL, id)) objc_msgSend;
response(self.target, self.successAction, category);

To:

void (*response)(id, SEL, id) = (void (*)(id, SEL, id)) objc_msgSend;
response(self.target, self.successAction, category);

It fixes!! Or a one-line code thanks to this commit on github:

((void(*)(id, SEL, id))objc_msgSend)(self.target, self.successAction, category);


来源:https://stackoverflow.com/questions/21843500/obj-msgsend-function-pointer-crash-when-build-with-64bit-arm64

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