cocos2d-x Touch Even crashes

cocos2d-x Touch Even crashes
0.0 0


I use android ndk r7 with cocos2d-x-1.0.1 version for android kindle fire. I enabled the self->setIsTouchEnabled(true);

void HelloWorld::registerWithTouchDispatcher() {
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);

then when run the program on the device and I click on the screen, the program crashes and exit.

Anyone knows what the problem is? I am very new to android and cocos2d-x. I used cocos2d-iphone and ever had any problem like this.



There would be several potential reasons, logs are required. But it’s nothing about ndk r7, we released our FishingJoy based on cocos2d-0.11.0 & ndk r7, it runs smoothly.
The 1st point is is that, this->setIsTouchEnabled(true) is the mechanic for “standard touch delegate”, wile registerWithTouchDispatcher is another mechanic for “targeted touch delegate”. You can learn their difference from here[]=touch&s[]=delegate I have never use them synchronously in one layer, so I don’t know what the result would be.
Second, pay attention to release/retain/autorelease of your layer, invoking methods of a released object would raise a crash in cpp, while in objective-c it’s safe.


What’s HelloWorld?
Is it the HelloWorld project?


I’d experienced it too, just run helloworld , crashes because of ccmenu
only ndk r7 in android


Why register a layer as targeted delegate?


I’m just a complete noob with cocos2d-x, but I believe this has something to do with the code generated by the create-android-project script. If I open HelloWorld from the cocos2d-x folder, run the build-native script and then create the project in Eclipse and run it, it works perfectly. However, if I create a new project with the create-android-project script and do the same steps, the application runs but whenever I tap anywhere on the screen the application quits without any error in the console. I’m running Android SDK 4, NDK r7 on MacOS X, using a 2.3.3 AVD emulator.


I don’t think it is matter with ndk version, could you paste a demo to reproduce it?


Sure thing, here’s the link

Please note though that this is EXACTLY the output of, I haven’t changed a single line of code. The only thing I did was run build_native, open the project in Eclipse and run it. Thanks!


Hi Minggo Zhang: Walzer helped me to make it work. But I still don’t know what was the problem. since he sent me back the project after the modification, I run it on my kindler fire, it works. then I copied to Classes and Resources directories into my own project, the problem is still there (touch the screen and the app exit) .

So I just use the project Walzer sent to me and modified the configurations files to match my development env, then compiled the project and run it , the app seems like ok.

I still don’t know what is wrong with my project.



there is another guy in cocos2d-iphone group also had the same problem.


Please discuss this issue in the new thread.

I think they are the same issue.