mirror of https://github.com/axmolengine/axmol.git
Add test case for issue#9898
This commit is contained in:
parent
de645a7c9c
commit
13481ea5c2
|
@ -28,7 +28,8 @@ std::function<Layer*()> createFunctions[] =
|
||||||
CL(Issue4129),
|
CL(Issue4129),
|
||||||
CL(Issue4160),
|
CL(Issue4160),
|
||||||
CL(DanglingNodePointersTest),
|
CL(DanglingNodePointersTest),
|
||||||
CL(RegisterAndUnregisterWhileEventHanldingTest)
|
CL(RegisterAndUnregisterWhileEventHanldingTest),
|
||||||
|
CL(Issue9898)
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]);
|
unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]);
|
||||||
|
@ -1454,3 +1455,36 @@ std::string RegisterAndUnregisterWhileEventHanldingTest::subtitle() const
|
||||||
{
|
{
|
||||||
return "Tap the square multiple times - should not crash!";
|
return "Tap the square multiple times - should not crash!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Issue9898::Issue9898()
|
||||||
|
{
|
||||||
|
auto origin = Director::getInstance()->getVisibleOrigin();
|
||||||
|
auto size = Director::getInstance()->getVisibleSize();
|
||||||
|
|
||||||
|
auto nodeA = Node::create();
|
||||||
|
addChild(nodeA);
|
||||||
|
|
||||||
|
_listener = cocos2d::EventListenerCustom::create("Issue9898", [&](cocos2d::EventCustom *event){
|
||||||
|
_eventDispatcher->removeEventListener(_listener);
|
||||||
|
_eventDispatcher->dispatchCustomEvent("Issue9898");
|
||||||
|
});
|
||||||
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, nodeA);
|
||||||
|
|
||||||
|
auto menuItem = MenuItemFont::create("Dispatch Custom Event", [&](Ref *sender) {
|
||||||
|
_eventDispatcher->dispatchCustomEvent("Issue9898");
|
||||||
|
});
|
||||||
|
menuItem->setPosition(origin.x + size.width/2, origin.y + size.height/2);
|
||||||
|
auto menu = Menu::create(menuItem, nullptr);
|
||||||
|
menu->setPosition(Vec2::ZERO);
|
||||||
|
addChild(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Issue9898::title() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Issue9898::subtitle() const
|
||||||
|
{
|
||||||
|
return "Should not crash if dispatch event after remove\n event listener in callback";
|
||||||
|
}
|
||||||
|
|
|
@ -227,4 +227,17 @@ public:
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Issue9898 : public EventDispatcherTestDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(Issue9898);
|
||||||
|
Issue9898();
|
||||||
|
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
EventListenerCustom* _listener;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* defined(__samples__NewEventDispatcherTest__) */
|
#endif /* defined(__samples__NewEventDispatcherTest__) */
|
||||||
|
|
Loading…
Reference in New Issue