mirror of https://github.com/axmolengine/axmol.git
Fixed crashes in test case of Scene/Node.
This commit is contained in:
parent
2e24f302d6
commit
16bce0bfd3
|
@ -336,7 +336,6 @@ void StressTest1::shouldNotCrash(float dt)
|
||||||
// remove
|
// remove
|
||||||
void StressTest1::removeMe(Node* node)
|
void StressTest1::removeMe(Node* node)
|
||||||
{
|
{
|
||||||
getParent()->removeChild(node, true);
|
|
||||||
getTestSuite()->enterNextTest();
|
getTestSuite()->enterNextTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,23 +69,14 @@ SceneTestLayer1::~SceneTestLayer1()
|
||||||
|
|
||||||
void SceneTestLayer1::onPushScene(Ref* sender)
|
void SceneTestLayer1::onPushScene(Ref* sender)
|
||||||
{
|
{
|
||||||
auto scene = new (std::nothrow) SceneTestScene();
|
auto scene = SceneTestScene::create(2);
|
||||||
auto layer = new (std::nothrow) SceneTestLayer2();
|
|
||||||
scene->addChild( layer, 0 );
|
|
||||||
Director::getInstance()->pushScene( scene );
|
Director::getInstance()->pushScene( scene );
|
||||||
scene->release();
|
|
||||||
layer->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneTestLayer1::onPushSceneTran(Ref* sender)
|
void SceneTestLayer1::onPushSceneTran(Ref* sender)
|
||||||
{
|
{
|
||||||
auto scene = new (std::nothrow) SceneTestScene();
|
auto scene = SceneTestScene::create(2);
|
||||||
auto layer = new (std::nothrow) SceneTestLayer2();
|
|
||||||
scene->addChild( layer, 0 );
|
|
||||||
|
|
||||||
Director::getInstance()->pushScene( TransitionSlideInT::create(1, scene) );
|
Director::getInstance()->pushScene( TransitionSlideInT::create(1, scene) );
|
||||||
scene->release();
|
|
||||||
layer->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,21 +135,14 @@ void SceneTestLayer2::onGoBack(Ref* sender)
|
||||||
|
|
||||||
void SceneTestLayer2::onReplaceScene(Ref* sender)
|
void SceneTestLayer2::onReplaceScene(Ref* sender)
|
||||||
{
|
{
|
||||||
auto scene = new (std::nothrow) SceneTestScene();
|
auto scene = SceneTestScene::create(3);
|
||||||
auto layer = SceneTestLayer3::create();
|
|
||||||
scene->addChild( layer, 0 );
|
|
||||||
Director::getInstance()->replaceScene( scene );
|
Director::getInstance()->replaceScene( scene );
|
||||||
scene->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SceneTestLayer2::onReplaceSceneTran(Ref* sender)
|
void SceneTestLayer2::onReplaceSceneTran(Ref* sender)
|
||||||
{
|
{
|
||||||
auto scene = new (std::nothrow) SceneTestScene();
|
auto scene = SceneTestScene::create(3);
|
||||||
auto layer = SceneTestLayer3::create();
|
|
||||||
scene->addChild( layer, 0 );
|
|
||||||
Director::getInstance()->replaceScene( TransitionFlipX::create(2, scene) );
|
Director::getInstance()->replaceScene( TransitionFlipX::create(2, scene) );
|
||||||
scene->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
@ -228,13 +212,32 @@ void SceneTestLayer3::item3Clicked(Ref* sender)
|
||||||
Director::getInstance()->popToSceneStackLevel(2);
|
Director::getInstance()->popToSceneStackLevel(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SceneTestScene::init()
|
SceneTestScene* SceneTestScene::create(int testIndex /* = 1 */)
|
||||||
{
|
{
|
||||||
if (TestCase::init())
|
auto scene = new (std::nothrow) SceneTestScene;
|
||||||
|
if (scene && scene->init())
|
||||||
{
|
{
|
||||||
addChild(SceneTestLayer1::create());
|
scene->autorelease();
|
||||||
return true;
|
switch (testIndex)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
scene->addChild(SceneTestLayer1::create());
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
scene->addChild(SceneTestLayer2::create());
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
scene->addChild(SceneTestLayer3::create());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete scene;
|
||||||
|
scene = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ class SceneTestLayer1 : public cocos2d::Layer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CREATE_FUNC(SceneTestLayer1);
|
CREATE_FUNC(SceneTestLayer1);
|
||||||
|
|
||||||
SceneTestLayer1();
|
SceneTestLayer1();
|
||||||
~SceneTestLayer1();
|
~SceneTestLayer1();
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ class SceneTestLayer2 : public cocos2d::Layer
|
||||||
float _timeCounter;
|
float _timeCounter;
|
||||||
public:
|
public:
|
||||||
CREATE_FUNC(SceneTestLayer2);
|
CREATE_FUNC(SceneTestLayer2);
|
||||||
|
|
||||||
SceneTestLayer2();
|
SceneTestLayer2();
|
||||||
|
|
||||||
void testDealloc(float dt);
|
void testDealloc(float dt);
|
||||||
|
@ -39,8 +41,10 @@ class SceneTestLayer3 : public cocos2d::LayerColor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CREATE_FUNC(SceneTestLayer3);
|
CREATE_FUNC(SceneTestLayer3);
|
||||||
|
|
||||||
SceneTestLayer3();
|
SceneTestLayer3();
|
||||||
bool init();
|
|
||||||
|
virtual bool init() override;
|
||||||
virtual void testDealloc(float dt);
|
virtual void testDealloc(float dt);
|
||||||
void item0Clicked(cocos2d::Ref* sender);
|
void item0Clicked(cocos2d::Ref* sender);
|
||||||
void item1Clicked(cocos2d::Ref* sender);
|
void item1Clicked(cocos2d::Ref* sender);
|
||||||
|
@ -51,9 +55,7 @@ public:
|
||||||
class SceneTestScene : public TestCase
|
class SceneTestScene : public TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CREATE_FUNC(SceneTestScene);
|
static SceneTestScene* create(int testIndex = 1);
|
||||||
|
|
||||||
virtual bool init() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue