Kinematic motion state crash

yz-online
Posts: 3
Joined: Mon Oct 24, 2011 11:00 am

Kinematic motion state crash

Post by yz-online »

Hi all, i ve recently a strange problem with my kinematic motion state:

Code: Select all

#ifndef _OGRE_KINEMATIC_MOTION_STATE_H_
#define _OGRE_KINEMATIC_MOTION_STATE_H_

#include <OgreSceneNode.h>
#include "linearmath\btmotionstate.h"

class OgreKinematicMotionState : public btMotionState {
public:

		OgreKinematicMotionState(Ogre::SceneNode* ogreNode) {
			this->node = ogreNode;
                        btTransform trans;
	                trans.setIdentity();
			this->transform = trans;
		}

		virtual ~OgreKinematicMotionState();

		virtual void getWorldTransform(btTransform &worldTrans) const {
			worldTrans = this->transform;
		}

		void setKinematicPos(btTransform &currentPos) {
                        //crash here, any access to this->transform make application crash
			std::cout << this->transform.getOrigin().getX() <<std::endl;
			this->transform = currentPos;
			btVector3 pos = currentPos.getOrigin();
			this->node->setPosition(pos.getX(), pos.getY(), pos.getZ());
		}

    virtual void setWorldTransform(const btTransform &worldTrans) { }*/


protected:

    /**
    * Node to synchronize with the wrapped btTransform object.
    */
    Ogre::SceneNode* node;

    /**
    * Contains position and orientation data.
    */
    btTransform transform;
};

#endif

any idea?
User avatar
jarno
Posts: 57
Joined: Tue Mar 16, 2010 1:42 am

Re: Kinematic motion state crash

Post by jarno »

Something is calling setKinematicPos using a NULL pointer instead of a valid pointer to a OgreKinematicMotionState object.

Set a breakpoint at the start of setKinematicPos and look through the callstack to see why the pointer is NULL.

---JvdL---
yz-online
Posts: 3
Joined: Mon Oct 24, 2011 11:00 am

Re: Kinematic motion state crash

Post by yz-online »

Thanks for your quick answer but the param is always ok, no problem with it, the problem is coming from the transform attribute

even this->transform = currentPos; cause the crash(and i ve checked currentPos, it is a valid btTransform)
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Kinematic motion state crash

Post by mi076 »

the idea is not to have "this->" in the constructor... it may work or not... you don't need it here - no masking so far, isn't it?
http://www.parashift.com/c++-faq-lite/c ... l#faq-10.7

this worked for me

Code: Select all

class MyKinematicMotionState : public btMotionState
{

public:

    MyKinematicMotionState(const btTransform & initialpos)
    {
    mPos1 = initialpos;
    }

    ~MyKinematicMotionState()
    {
    }

    void getWorldTransform(btTransform & worldTrans) const
    {
    worldTrans = mPos1;
    }

    void setKinematicPos(btTransform & currentPos)
    {
    mPos1 = currentPos;
    }

    void setWorldTransform(const btTransform & worldTrans)
    {
    mPos1 = worldTrans;
    }

protected:

btTransform mPos1;
};
yz-online
Posts: 3
Joined: Mon Oct 24, 2011 11:00 am

Re: Kinematic motion state crash

Post by yz-online »

finally found it:

it did not like OgreKinematicMotionState* state = static_cast<OgreKinematicMotionState*>(body->getMotionState());