fix createVisualShape.py ray vertical/horizontal and retina scale, fixes Issue 2085

fix memory leak in removeBody, fixes issue 2086
This commit is contained in:
erwincoumans
2019-01-30 15:29:43 -08:00
parent 9392b05d53
commit 014c68388e
3 changed files with 15 additions and 9 deletions

View File

@@ -1043,12 +1043,12 @@ bool OpenGLGuiHelper::getCameraInfo(int* width, int* height, float viewMatrix[16
btScalar aspect = float(*width) / float(*height); btScalar aspect = float(*width) / float(*height);
hori *= aspect; hori *= aspect;
//compute 'hor' and 'vert' vectors, useful to generate raytracer rays //compute 'hor' and 'vert' vectors, useful to generate raytracer rays
hor[0] = hori[0]; hor[0] = hori[0]* m_data->m_glApp->m_window->getRetinaScale();
hor[1] = hori[1]; hor[1] = hori[1]* m_data->m_glApp->m_window->getRetinaScale();
hor[2] = hori[2]; hor[2] = hori[2]* m_data->m_glApp->m_window->getRetinaScale();
vert[0] = vertical[0]; vert[0] = vertical[0]* m_data->m_glApp->m_window->getRetinaScale();
vert[1] = vertical[1]; vert[1] = vertical[1]* m_data->m_glApp->m_window->getRetinaScale();
vert[2] = vertical[2]; vert[2] = vertical[2]* m_data->m_glApp->m_window->getRetinaScale();
*yaw = getRenderInterface()->getActiveCamera()->getCameraYaw(); *yaw = getRenderInterface()->getActiveCamera()->getCameraYaw();
*pitch = getRenderInterface()->getActiveCamera()->getCameraPitch(); *pitch = getRenderInterface()->getActiveCamera()->getCameraPitch();

View File

@@ -9234,10 +9234,12 @@ bool PhysicsServerCommandProcessor::processRemoveBodyCommand(const struct Shared
m_data->m_dynamicsWorld->removeCollisionObject(bodyHandle->m_multiBody->getBaseCollider()); m_data->m_dynamicsWorld->removeCollisionObject(bodyHandle->m_multiBody->getBaseCollider());
int graphicsIndex = bodyHandle->m_multiBody->getBaseCollider()->getUserIndex(); int graphicsIndex = bodyHandle->m_multiBody->getBaseCollider()->getUserIndex();
m_data->m_guiHelper->removeGraphicsInstance(graphicsIndex); m_data->m_guiHelper->removeGraphicsInstance(graphicsIndex);
delete bodyHandle->m_multiBody->getBaseCollider();
} }
for (int link = 0; link < bodyHandle->m_multiBody->getNumLinks(); link++) for (int link = 0; link < bodyHandle->m_multiBody->getNumLinks(); link++)
{ {
if (bodyHandle->m_multiBody->getLink(link).m_collider) btCollisionObject* colObj = bodyHandle->m_multiBody->getLink(link).m_collider;
if (colObj)
{ {
if (m_data->m_pluginManager.getRenderInterface()) if (m_data->m_pluginManager.getRenderInterface())
{ {
@@ -9246,12 +9248,12 @@ bool PhysicsServerCommandProcessor::processRemoveBodyCommand(const struct Shared
m_data->m_dynamicsWorld->removeCollisionObject(bodyHandle->m_multiBody->getLink(link).m_collider); m_data->m_dynamicsWorld->removeCollisionObject(bodyHandle->m_multiBody->getLink(link).m_collider);
int graphicsIndex = bodyHandle->m_multiBody->getLink(link).m_collider->getUserIndex(); int graphicsIndex = bodyHandle->m_multiBody->getLink(link).m_collider->getUserIndex();
m_data->m_guiHelper->removeGraphicsInstance(graphicsIndex); m_data->m_guiHelper->removeGraphicsInstance(graphicsIndex);
delete colObj;
} }
} }
int numCollisionObjects = m_data->m_dynamicsWorld->getNumCollisionObjects(); int numCollisionObjects = m_data->m_dynamicsWorld->getNumCollisionObjects();
m_data->m_dynamicsWorld->removeMultiBody(bodyHandle->m_multiBody); m_data->m_dynamicsWorld->removeMultiBody(bodyHandle->m_multiBody);
numCollisionObjects = m_data->m_dynamicsWorld->getNumCollisionObjects(); numCollisionObjects = m_data->m_dynamicsWorld->getNumCollisionObjects();
//todo: clear all other remaining data, release memory etc
delete bodyHandle->m_multiBody; delete bodyHandle->m_multiBody;
bodyHandle->m_multiBody = 0; bodyHandle->m_multiBody = 0;

View File

@@ -36,6 +36,10 @@ public:
btMultiBody* m_multiBody; btMultiBody* m_multiBody;
int m_link; int m_link;
virtual ~btMultiBodyLinkCollider()
{
}
btMultiBodyLinkCollider(btMultiBody* multiBody, int link) btMultiBodyLinkCollider(btMultiBody* multiBody, int link)
: m_multiBody(multiBody), : m_multiBody(multiBody),
m_link(link) m_link(link)