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:
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
Strange Behaviour in Release Only
-
- Posts: 83
- Joined: Mon Nov 05, 2018 8:16 am
- Location: China
Re: Strange Behaviour in Release Only
Could you provide a simple test then i can work with you?
-
- Posts: 17
- Joined: Wed Dec 21, 2016 1:15 pm
-
- Posts: 17
- Joined: Wed Dec 21, 2016 1:15 pm
Re: Strange Behaviour in Release Only
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:
Working MotionState cpp
Broken MotionState header:
Broken MotionState cpp:
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.
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
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()
{
}
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
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()));
}
Thanks.
-
- Posts: 83
- Joined: Mon Nov 05, 2018 8:16 am
- Location: China
Re: Strange Behaviour in Release Only
i only find the include file is differnent, btBulletCollisionCommon.h vs. btBulletDynamicsCommon.h. i don't known why it cause this strange behaviour.
-
- Posts: 96
- Joined: Wed Mar 16, 2016 10:11 am
Re: Strange Behaviour in Release Only
probably uninitialized value in some fields of btTransform
In C++, a variable that is not assigned to any value will usually be = 0, but only in debug mode.
In release mode, it will usually be an ugly random value.
In C++, a variable that is not assigned to any value will usually be = 0, but only in debug mode.
In release mode, it will usually be an ugly random value.
-
- Posts: 33
- Joined: Sun May 20, 2018 3:09 pm
Re: Strange Behaviour in Release Only
I also found that by upgrading Visual Studio from 2017 to 2019, I realized that I had some unitialized variables as well - VS2017 was somehow setting them to 0 even in release mode, but VS2019 does not
I wonder if it was a compiler/linker setting
weird
I wonder if it was a compiler/linker setting
weird