From 8feb3a731b000d968232b87a3f32c41dea6f9645 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 18 Nov 2013 21:28:40 +0800 Subject: [PATCH] issue #2771: fix physics test crashes --- .../Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp index 70e003a87d..a9eca9a6ad 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -368,26 +368,25 @@ bool PhysicsDemo::onTouchBegan(Touch* touch, Event* event) auto location = touch->getLocation(); Array* arr = _scene->getPhysicsWorld()->getShapes(location); - PhysicsShape* shape = nullptr; + PhysicsBody* body = nullptr; for (Object* obj : *arr) { - shape = dynamic_cast(obj); - - if ((shape->getTag() & DRAG_BODYS_TAG) != 0) + if ((dynamic_cast(obj)->getBody()->getTag() & DRAG_BODYS_TAG) != 0) { + body = dynamic_cast(obj)->getBody(); break; } } - if (shape != nullptr) + if (body != nullptr) { Node* mouse = Node::create(); mouse->setPhysicsBody(PhysicsBody::create(PHYSICS_INFINITY, PHYSICS_INFINITY)); mouse->getPhysicsBody()->setDynamic(false); mouse->setPosition(location); this->addChild(mouse); - PhysicsJointPin* joint = PhysicsJointPin::construct(mouse->getPhysicsBody(), shape->getBody(), location); - joint->setMaxForce(5000.0f * shape->getBody()->getMass()); + PhysicsJointPin* joint = PhysicsJointPin::construct(mouse->getPhysicsBody(), body, location); + joint->setMaxForce(5000.0f * body->getMass()); _scene->getPhysicsWorld()->addJoint(joint); _mouses.insert(std::make_pair(touch->getID(), mouse));