Skip to content

EventDispatcher have a BUG! #11476

Open
Open
@JasonLion-CN

Description

@JasonLion-CN

When EventDispatcher is in working(flag _inDispatch == 1) and removeEventListener is called:

if (_inDispatch == 0)
{
listeners->erase(iter);
CC_SAFE_RELEASE(l);
}

its mean the listener was not be remove from listeners,until updateListeners to be call 。

In the dispatchTouchEvent member functionc:
sortEventListeners() to cause Gt0Index be set: listeners->setGt0Index(index)

then, updateListeners to call and remove listener that not remove before, so that the size of fixedPriorityListeners is change.

so cause the assert to failed.
CCASSERT(listeners->getGt0Index() <= static_cast<ssize_t>(fixedPriorityListeners->size()), "Out of range exception!"); (line:734)

Activity

added this to the unconfirmed milestone on Apr 23, 2015
voiddog

voiddog commented on Apr 29, 2016

@voiddog

There is a _priorityDirtyFlagMap in the CCEventDispatcher.cpp, at the end of dispatchEvent(event), it will called updateListeners(event);

In the updateListeners(event), it will remove the listener whitch is unregistered. But the cocos did not set the dity flag to DirtyFlag::SCENE_GRAPH_PRIORITY or DirtyFlag::FIXED_PRIORITY.

To resolve this bug, I add two sentences to the updateListeners(Event *event):

...
iter = sceneGraphPriorityListeners->erase(iter);
// line (1161)
setDirty(l->getListenerID(), DirtyFlag::SCENE_GRAPH_PRIORITY);
...
iter = fixedPriorityListeners->erase(iter);
// line (1183)
setDirty(l->getListenerID(), DirtyFlag::FIXED_PRIORITY);
...
removed this from the unconfirmed milestone on Aug 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @walzer@minggo@voiddog@JasonLion-CN

        Issue actions

          EventDispatcher have a BUG! · Issue #11476 · cocos2d/cocos2d-x