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
|
||||
void StressTest1::removeMe(Node* node)
|
||||
{
|
||||
getParent()->removeChild(node, true);
|
||||
getTestSuite()->enterNextTest();
|
||||
}
|
||||
|
||||
|
|
|
@ -69,23 +69,14 @@ SceneTestLayer1::~SceneTestLayer1()
|
|||
|
||||
void SceneTestLayer1::onPushScene(Ref* sender)
|
||||
{
|
||||
auto scene = new (std::nothrow) SceneTestScene();
|
||||
auto layer = new (std::nothrow) SceneTestLayer2();
|
||||
scene->addChild( layer, 0 );
|
||||
auto scene = SceneTestScene::create(2);
|
||||
Director::getInstance()->pushScene( scene );
|
||||
scene->release();
|
||||
layer->release();
|
||||
}
|
||||
|
||||
void SceneTestLayer1::onPushSceneTran(Ref* sender)
|
||||
{
|
||||
auto scene = new (std::nothrow) SceneTestScene();
|
||||
auto layer = new (std::nothrow) SceneTestLayer2();
|
||||
scene->addChild( layer, 0 );
|
||||
|
||||
auto scene = SceneTestScene::create(2);
|
||||
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)
|
||||
{
|
||||
auto scene = new (std::nothrow) SceneTestScene();
|
||||
auto layer = SceneTestLayer3::create();
|
||||
scene->addChild( layer, 0 );
|
||||
auto scene = SceneTestScene::create(3);
|
||||
Director::getInstance()->replaceScene( scene );
|
||||
scene->release();
|
||||
}
|
||||
|
||||
|
||||
void SceneTestLayer2::onReplaceSceneTran(Ref* sender)
|
||||
{
|
||||
auto scene = new (std::nothrow) SceneTestScene();
|
||||
auto layer = SceneTestLayer3::create();
|
||||
scene->addChild( layer, 0 );
|
||||
auto scene = SceneTestScene::create(3);
|
||||
Director::getInstance()->replaceScene( TransitionFlipX::create(2, scene) );
|
||||
scene->release();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -228,13 +212,32 @@ void SceneTestLayer3::item3Clicked(Ref* sender)
|
|||
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());
|
||||
return true;
|
||||
scene->autorelease();
|
||||
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:
|
||||
CREATE_FUNC(SceneTestLayer1);
|
||||
|
||||
SceneTestLayer1();
|
||||
~SceneTestLayer1();
|
||||
|
||||
|
@ -27,6 +28,7 @@ class SceneTestLayer2 : public cocos2d::Layer
|
|||
float _timeCounter;
|
||||
public:
|
||||
CREATE_FUNC(SceneTestLayer2);
|
||||
|
||||
SceneTestLayer2();
|
||||
|
||||
void testDealloc(float dt);
|
||||
|
@ -39,8 +41,10 @@ class SceneTestLayer3 : public cocos2d::LayerColor
|
|||
{
|
||||
public:
|
||||
CREATE_FUNC(SceneTestLayer3);
|
||||
|
||||
SceneTestLayer3();
|
||||
bool init();
|
||||
|
||||
virtual bool init() override;
|
||||
virtual void testDealloc(float dt);
|
||||
void item0Clicked(cocos2d::Ref* sender);
|
||||
void item1Clicked(cocos2d::Ref* sender);
|
||||
|
@ -51,9 +55,7 @@ public:
|
|||
class SceneTestScene : public TestCase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SceneTestScene);
|
||||
|
||||
virtual bool init() override;
|
||||
static SceneTestScene* create(int testIndex = 1);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue