pure virtual method called: addRigidBody

Post Reply
rookie86
Posts: 1
Joined: Thu Oct 03, 2013 9:14 am

pure virtual method called: addRigidBody

Post by rookie86 »

I've started with a simple tutorial, this works without problems:

working code

Code: Select all

//...
                //create World
		btDefaultCollisionConfiguration* config = new btDefaultCollisionConfiguration();
		btCollisionDispatcher* dispatcher = new btCollisionDispatcher(config);
		btBroadphaseInterface* broadphase = new btDbvtBroadphase();
		btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
		btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, config);
		world->setGravity(btVector3(0,-10,0));		

		//create Object
		btCollisionShape* shape = new btBoxShape(btVector3(1,3,1));
		btTransform transform;
		transform.setIdentity();
		btVector3 localInertia(0,0,0);
		shape->calculateLocalInertia(40.0f, localInertia);
	    btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(50,50,50)));		
		btRigidBody* body = new btRigidBody( btRigidBody::btRigidBodyConstructionInfo(40.0f, motionState,shape, localInertia));
	
		world->addRigidBody(body);
		
		btVector3 position = body->getCenterOfMassPosition();

		std::cout << position.getX() << " " << position.getY() << " " << position.getZ() << std::endl;

		for(int i = 0; i < 100; ++i)
		{
			world->stepSimulation(6,10);		
			position = body->getCenterOfMassPosition();
			std::cout << position.getX() << " " << position.getY() << " " << position.getZ() << std::endl;		
		}
//...
Now i want to have all the world code in one class:

Code: Select all

class World
{
	btDefaultCollisionConfiguration*		m_Config;
	btCollisionDispatcher*					m_Dispatcher;
	btBroadphaseInterface*					m_Interface;
	btSequentialImpulseConstraintSolver*	m_Solver;
	btDiscreteDynamicsWorld*				m_World;
	
	public:
	World() 
	{
			m_Config     = NULL;
			m_Dispatcher = NULL;
			m_Interface  = NULL;
			m_Solver     = NULL;
			m_World      = NULL;	
	}

	void init()
	{
		m_Config = new btDefaultCollisionConfiguration();
		m_Dispatcher = new btCollisionDispatcher(m_Config);
		m_Interface = new btDbvtBroadphase();
		m_Solver = new btSequentialImpulseConstraintSolver();
		m_World = new btDiscreteDynamicsWorld(m_Dispatcher, m_Interface, m_Solver, m_Config);
		m_World->setGravity(btVector3(0,-10,0));		
	}

	~World() 
	{
		delete m_Config;
		delete m_Dispatcher;
		delete m_Solver;
		delete m_Interface;
		delete m_World;		
	}

	void addObject(btRigidBody* body)
	{
		m_World->addRigidBody(body);	
	}

	void update()
	{
		m_World->stepSimulation(20,10);	
	}

};
It compiles without problems but if i do WorldObject.addObject(object) on the same RigidBody i've created in the working code i get the following error message: "pure virtual method called terminate called without an active exception". If i comment out the "m_World->addRigidBody(body)" the code runs without problems. It looks like he calls the pure virtual function of btDynamicsWorld.

Can someone tell me where the problem is and how i can fix the problem?
Post Reply