Hi, I’m a Japanese game developer. I develop some games with cocos2d-x.
I’m confused by the following problem. So, if you any idea, please help me.
When tap the button put on a cocos2d-x layer, the button doesn’t work.
If the button be tapped, the call-back function of the button doesn’t be called.
I have found some workarounds of the problem. However, I have no idea why the problem occurs. And, I want the most suitable way, how to fix it.
The following are develop environment and mobile devices that the problem occurs.
[Develop environment]
- Operating system : Mac OS X El capitan(10.11.5)
- Xcode version : 7.3 - 7.3.1(7D1014)
- cocos2d-x version : cocos2d-x-3.2
- build config. : Test / Release
[Mobile devices]
- iPhone4s(iOS 9.3.2), iPhone5(iOS 9.3), iPad mini(iOS 9.3.1)
If mobile device’s condition (iOS version etc.) is different, the problem may not occur.
And, the apps built by Xcode 7.2.1 or older version have no problem. it work normally.
The problem doesn’t also occur with the apps built by Debug build mode.
I attach a sample code.
The button of the layer is made by ccbi (ccbi = cocos builder file).
The call-back function is referenced to the button by “Selector” in the ccbi file.
[About the sample Xcode project]
- Xcode Project name : CCBTest
- ccbi file: Resources/simple.ccbi
- Class file (written about layer) : Classes/SimpleView.h
Because the problem have not been resolved, so I use Xcode 7.2.1 now.
If you any idea, please give me.
Thank you for reading my question.
I have the same issue and my current solution is to set optimization flags for release build to -O1.
If you use cocosbuilder and your class inherits from CCBSelectorResolver, you can try disabling optimization for onResolveCCBCCMenuItemSelector by using [[clang::optnone]] instead.
After some investigation, I think that this bug is not related to cocos2d-x.
http://stackoverflow.com/questions/37718045/weird-behavior-with-multiple-inheritance-on-armv7s-devices
File github issue, might be something that cocos2d-x can code around, or provide documentation regarding this issue.
Hi, enrevol.
Thank you for answer. And, I’m sorry that I failed to attach the Sample Project files. (I have attached the url of github.)
I tried the way you said and CCMenuItem button work! I’m happy.
However, It’s difficult to disable optimization because of performance and size…
Thank you very much!
Hi, stevetranby.
Thank you for reply. I’m sorry that I failed to attach the Sample Project files. (I have attached the URL of github.)
I’ll try and find time to check into this one. Having a project to reference is great, thanks, but I actually just meant file an issue ( https://github.com/cocos2d/cocos2d-x/issues ) so that the actual dev team will more likely take a look (I’m just one of the community like you). If I test and find anything I’ll submit a PR, though.
Hi, stevetranby. I understand. I have submitted there.
Thank you very much for your kindness!
It may be that the compiler is optimizing out the functions that have no body, and then the multi-inheritance and likely pointer dereferencing function pointers is failing because it maybe treats them as the null pointer (0x00). Seems to match up with why the person’s stackoverflow issue is occuring since I believe the void func() method pointer is probably optimized away since it’s never used/called.
Try:
class SimpleView :
public cocos2d::Node,
public cocosbuilder::CCBSelectorResolver,
public cocosbuilder::CCBMemberVariableAssigner,
//public cocosbuilder::NodeLoaderListener,
//public cocosbuilder::CCBAnimationManagerDelegate
{
//void completedAnimationSequenceNamed(const char *name) override {}
//void onNodeLoaded(cocos2d::Node* pNode, cocosbuilder::NodeLoader* pNodeLoader) override {}
};
You could also comment out the inheriting from CCBMemberVariableAssigner and the assigner methods as well since you’re just re-implementing the virtual methods returning false. If you have other CCBI files that use the node loading, animation manager, or assign nodes in the cocos builder editor to variable names then you can re-inherit from them and add in methods that actually do something.
Hi, stevetranby. Thank you very much for your kindness !
I tried your suggestion.
However, the issue wasn’t be solved…
Hmm, bummer. Seemed to work on the simulators for 4s and 5 so thought maybe … I’ll see if I can find my old 4s phone to test with on hardware.