cocos2d-x 3.0 rc0
I use chipmunk, as cocos2d-x physics integration.
but I got an error, when I replace scene while two bodies have contacted.
File:CCScheduler.cpp
Line:470
Expression:hashElement->entry->markedForDeletion
How can I fix it?
Below simple test code
``` #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__#include “cocos2d.h”
class HelloWorld : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
CREATE_FUNC(HelloWorld);
bool onContactBegin(const cocos2d::PhysicsContact& contact);
};
#endif // HELLOWORLD_SCENE_H
<cpp>
#include “HelloWorldScene.h”
USING_NS_CC;
Scene* HelloWorld::createScene()
{
auto scene = Scene::createWithPhysics();
// Set Physics World
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL); // Set debug Draw
scene->getPhysicsWorld()->setGravity(Vect::ZERO); //set Gravity
// Set Boundary as Screen Size
Size visibleSize = Director::getInstance()->getVisibleSize();
auto body = PhysicsBody::createEdgeBox(visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 1);
body->setGroup(-100);
auto edgeNode = Node::create();
edgeNode->setPosition(Point(visibleSize.width/2,visibleSize.height/2));
edgeNode->setPhysicsBody(body);
scene->addChild(edgeNode,0);
//Layer
auto layer = HelloWorld::create();
scene->addChild(layer, -1);
return scene;
}
// on “init” you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
// sprite1
auto heroSpr = Sprite::create("test.png");
heroSpr->setPosition(100,160);
auto body = PhysicsBody::createCircle(heroSpr->getContentSize().width/2);
body->setGroup(100);
body->setContactTestBitmask(0xFFFFFFFF);
heroSpr->setPhysicsBody(body);
this->addChild(heroSpr,1);
// sprite2
auto targetSpr = Sprite::create("test.png");
targetSpr->setPosition(400,160);
auto body2 = PhysicsBody::createCircle(targetSpr->getContentSize().width/2);
body2->setGroup(100);
body2->setContactTestBitmask(0xFFFFFFFF);
targetSpr->setPhysicsBody(body2);
this->addChild(targetSpr,1);
targetSpr->runAction(MoveTo::create(3,Point(180,160)));
// contact
auto contactListener = EventListenerPhysicsContactWithGroup::create(100);
contactListener->onContactBegin = CC_CALLBACK_1(HelloWorld::onContactBegin, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(contactListener,100);
return true;
}
bool HelloWorld::onContactBegin(const PhysicsContact& contact)
{
Director::getInstance()->replaceScene(HelloWorld::createScene());
return true;
}