Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please more advice, if you feel good please support a lot of praise. Thank you! Hopy;)
The original code has been running on Xcode6.4 and iOS 8.4, and there's nothing wrong with it.
However, after running on iOS9.2 on Xcode7.2, an error occurs in the following methods:
//执行一个可变方法-(id)invokeSelectorNamed:(NSString *)selectorName{ SEL selector = NSSelectorFromString(selectorName); IMP imp = [self methodForSelector:selector]; id (*func)(id,SEL) = (void*)imp; return func(_gameScene.curMapNode,selector);}
The error type is i386 Universal protection error.
There are several places in the project that call the above methods, and the incoming selectorname are different. Later debugging found that only some selector calls would go wrong, while others never went wrong.
Carefully examine the selector code for the error, and find that the code does not return a value, whereas the Func prototype is the return value.
This shows that in Xcode7.2 the IMP call is checked, the function prototype is inconsistent, even if the return value is inconsistent, the call will go wrong.
Knowing the cause of the problem is simple enough to make each function prototype consistent, even if you return nil:
(NSString*)someFunc{ //原代码 returnnil;}
COCOSD Error in imp call on Xcode7 and iOS 9.2