Issue with touch - critical bug

Issue with touch - critical bug
0.0 0


@nite @slackmoehrle

Hi, it seems there is some issue in cocos2d-x core for handling touches.

We using cocos2d-x 3.15.1 C++ version, in our case we having issue on game over -> when user touching game screen and Interstitial ads from heyzapp appear - touches get disabled in game over screen.

After research we found that when Heyzapp ads appear cocos2d-x not sending touch end signal and it thinking that we still holding finger on screen . In cocos core exist such function:

static int getUnUsedIndex()
        int i;
        int temp = g_indexBitsUsed;
        for (i = 0; i < EventTouch::MAX_TOUCHES; i++) {
            if (! (temp & 0x00000001)) {
                g_indexBitsUsed |= (1 <<  i);
                return i;
            temp >>= 1;
        // all bits are used
        return -1;

Where MAX_TOUCHES = 15, so it means cocos can handle 15 such corrupted touches , so after 15 game overs when touch end not sent to cocos - touches get disabled in game and user can’t click anything ;/ I think there is some wrong observer logic which check if touch still active or not and stack with touches should be cleaned in some way.

IPad crashes when tapping with 10 fingers

i think it’s related to a similar problem i had. i broke it down to very few lines here:

if you checkout the previous version v3.15, it should work normal.


Seems like a serious issue, @zhangxm can you take a look?


@energyy Yep, we depend on end signal to know which finger is up. I think the problem is that, the end touch message is not sent.


Is there way to force send end signal or safely clean touches stack? otherwise touches stack get full with corrupted touches without touch end and touches get disabled in game when it gets full.


You can invoke Cocos2dxGLSurfaceView.onTouchEvent() and pass end signal, but i don’t think it is a good idea since this function is callback by system, and you make break things if not invoke it correctly. As i said above, why the end signal is missed?


You holding finger on screen and at this time Interstitial ad appear, you remove finger from screen but cocos2d-x still see like u holding finger on screen. If this happens 15 times, cocos2d-x thinking that there is 15t fingers on screen and after that it stoping to accept any touch. There is no way to send to cocos that finger is not on screen and it should remove from stack this event.


Yep, it seems a problem. May be we lost some message, but i have not idea where to remove the finger.