Page 1 of 1

Strange Behaviour in Release Only

Posted: Thu Mar 14, 2019 9:38 pm
by Apollo
Hi,

When I run my game in Debug in Visual Studio, all of the physics work perfectly. When I run it in Release, however, the collision shapes are completely wrong and therefore physics doesn't work as intended. There are no errors however when running in release so I'm unsure as to how to debug what's wrong. The image below shows the situation:
Image

I have just created a simple debugging scene to simplify the problem. The left image is in debug, where as you can see the cube has a simple btBoxShape surrounding it, and everything works fine. The two images on the right however are both in release. When running the application again and again, two different colliders are generated, neither of which are correct.

I have no idea what is causing the release build to be behaving so strangely, does anyone have any suggestions of either what's wrong, or of things I could try to work out what the problem is?

Thanks in advance

Re: Strange Behaviour in Release Only

Posted: Fri Mar 15, 2019 1:23 am
by steven
Could you provide a simple test then i can work with you?

Re: Strange Behaviour in Release Only

Posted: Fri Mar 15, 2019 7:38 am
by Apollo
steven wrote:
Fri Mar 15, 2019 1:23 am
Could you provide a simple test then i can work with you?
Yes that should be fine, I'll start working on a simple scene to upload as soon as possible. Thanks!

Re: Strange Behaviour in Release Only

Posted: Fri Mar 15, 2019 1:49 pm
by Apollo
In preparing a small sample that demonstrates the issue, I managed to identify that the problem was related to the motionState. When creating the sample, I temporarily used a btDefaultMotionState instead, and when I ran the program using it the collider was identical to in release. I can't understand why the motionstate would have that effect, as all it does is sync the physics for the object with Ogre, but there we go. Following this, I created a new motion state class using the example OgreMotionState from the Bullet wiki, which, as far as I can tell does everything exactly the same way I was doing things, but yet this new motion state class works in release but the original messes up the collider.

Working MotionState header:

Code: Select all

#ifndef NEW_MOTION_STATE_H
#define NEW_MOTION_STATE_H

#include <btBulletCollisionCommon.h>
#include <Ogre.h>

class NewMotionState : public btMotionState
{
	public:
		NewMotionState(const btTransform& _initialPosition, Ogre::SceneNode* _node);
		virtual ~NewMotionState();

		virtual void getWorldTransform(btTransform& _initialPosition) const;
		virtual void setWorldTransform(const btTransform& _worldTrans);

	protected:
		Ogre::SceneNode* m_sceneNode;
		btTransform m_initialPosition;
};

#endif
Working MotionState cpp

Code: Select all

#include "NewMotionState.h"

NewMotionState::NewMotionState(const btTransform& _initialPosition, Ogre::SceneNode* _sceneNode)
{
	m_sceneNode = _sceneNode;
	m_initialPosition = _initialPosition;
}

void NewMotionState::getWorldTransform(btTransform& _worldTrans) const
{
	_worldTrans = m_initialPosition;
}

void NewMotionState::setWorldTransform(const btTransform& _worldTrans)
{
	btQuaternion rot = _worldTrans.getRotation();
	m_sceneNode->setOrientation(Ogre::Quaternion(rot.w(), rot.x(), rot.y(), rot.z()));
	btVector3 pos = _worldTrans.getOrigin();
	m_sceneNode->setPosition(Ogre::Vector3(pos.x(), pos.y(), pos.z()));
}

NewMotionState::~NewMotionState()
{

}
Broken MotionState header:

Code: Select all

#ifndef TEST_MOTION_STATE_H
#define TEST_MOTION_STATE_H

#include <btBulletDynamicsCommon.h>
#include <Ogre.h>
class TestMotionState : public btMotionState
{
	public:
		TestMotionState(btTransform _transform, Ogre::SceneNode* _sn);
		virtual ~TestMotionState() {};

		virtual void setWorldTransform(const btTransform &_transform);
		virtual void getWorldTransform(btTransform& _transform) const;

	protected:
		btTransform m_initialPosition;
		Ogre::SceneNode* m_sn;
};

#endif
Broken MotionState cpp:

Code: Select all

#include "TestMotionState.h"

TestMotionState::TestMotionState(btTransform _transform, Ogre::SceneNode* _sn)
	m_initialPosition = _transform;
	m_sn = _sn;
}

void TestMotionState::getWorldTransform(btTransform& _transform) const
{
	_transform = m_initialPosition;
}

void TestMotionState::setWorldTransform(const btTransform& _transform)
{
	btQuaternion rot = _transform.getRotation();
	m_sn->setOrientation(Ogre::Quaternion(rot.w(), rot.x(), rot.y(), rot.z()));
	btVector3 pos = _transform.getOrigin();
	m_sn->setPosition(Ogre::Vector3(pos.x(), pos.y(), pos.z()));
}
As the new MotionState class is working, I think I'll just continue using that one, but if you can see anything that would have caused this strange behaviour, that would be very welcome too.

Thanks.

Re: Strange Behaviour in Release Only

Posted: Tue Mar 19, 2019 1:50 am
by steven
i only find the include file is differnent, btBulletCollisionCommon.h vs. btBulletDynamicsCommon.h. i don't known why it cause this strange behaviour.