calculateLocalInertia crash with only btConvexHullShape
Posted: Mon Dec 31, 2018 1:42 am
Hi.
I am working on my gamesystem, rewriting it to a better shape to be exact, and now I have a problem with the convex shape.
fortunately there is no problem with the other shapes, but if I want to build a btConvexHullShape, a lots of time it crash when it reach the
line with this error message:
So here is the initial code(the collisionshape definition is in the header, so I can reach it globally inside the class) :
and here is the code what is build up the convex shape:
The points what I give to the shape it's valid, and the objects are convex, simple boxes.
Some log for proof:
Maybe important information, the class is abstact.
I use Visual studio 2017 with Ogre 1.9 and the Bulletphysics version is 2.83.7
I am working on my gamesystem, rewriting it to a better shape to be exact, and now I have a problem with the convex shape.
fortunately there is no problem with the other shapes, but if I want to build a btConvexHullShape, a lots of time it crash when it reach the
Code: Select all
"collisionshape->calculateLocalInertia(mass, localinertia); "
But if it not crash, it work like a charm, without any problem, however it never crash with other shapes.Unhandled exception at 0x00A6C2FE in PlayGround.exe: 0xC0000005: Access violation reading location 0xFFFFFFFF. occurred
So here is the initial code(the collisionshape definition is in the header, so I can reach it globally inside the class) :
Code: Select all
string shapetype = "box";
if (functions.searchinvector("hitboxtype", configuration, tablecoord)) shapetype = configuration[tablecoord + 1];
size = Ogre::Vector3(1, 1, 1);
position = itemnode->_getDerivedPosition();
quaternion = itemnode->_getDerivedOrientation();
mass = 0;
localinertia = btVector3(0, 0, 0);
radius = 1;
if (functions.searchinvector("radsize", configuration, tablecoord))radius = functions.converttodouble(configuration[tablecoord + 1]);
if (functions.searchinvector("size", configuration, tablecoord))
{
size.x = functions.converttodouble(configuration[tablecoord + 1]);
size.y = functions.converttodouble(configuration[tablecoord + 2]);
size.z = functions.converttodouble(configuration[tablecoord + 3]);
}
if (functions.searchinvector("mass", configuration, tablecoord)) mass = functions.converttofloat(configuration[tablecoord + 1]);
if (functions.searchinvector("localinertia", configuration, tablecoord))
{
localinertia.setX(btScalar(functions.converttofloat(configuration[tablecoord + 1])));
localinertia.setY(btScalar(functions.converttofloat(configuration[tablecoord + 2])));
localinertia.setZ(btScalar(functions.converttofloat(configuration[tablecoord + 3])));
}
btTransform transform; transform.setIdentity();
transform.setOrigin(btVector3(btScalar(position.x), btScalar(position.y), btScalar(position.z)));//position
transform.setRotation(btQuaternion(btScalar(quaternion.x), btScalar(quaternion.y), btScalar(quaternion.z), btScalar(quaternion.w)));
btDefaultMotionState *motionstate = new btDefaultMotionState(transform);
_setcollisionshape(shapetype);//here I call the shape functions
functions.log("after _setcollisionshape "+functions.converttostring(mass)+" - " + functions.converttostring(localinertia.getX()));
int stupidname = collisionshape->getShapeType();
functions.log("name: "+functions.converttostring(stupidname));
collisionshape->calculateLocalInertia(mass, localinertia);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionstate, collisionshape, localinertia);
Code: Select all
collisionshape = new btConvexHullShape();
for (size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
{
posElem->baseVertexPointerToElement(vertex, &pReal);
Ogre::Vector3 pt(pReal[0], pReal[1], pReal[2]);
functions.log("pt["+ functions.converttostring(j)+"]: x: " + functions.converttostring(pReal[0]) + " y: " + functions.converttostring(pReal[1]) + "z: " + functions.converttostring(pReal[2]));
btVector3 btv = btVector3(pReal[0], pReal[1], pReal[2]);
((btConvexHullShape*)collisionshape)->addPoint(btv);
}
Some log for proof:
Code: Select all
02:12:49: before _setcollisionshape
02:12:49: the Convex one
02:12:49: pt[0]: x: 0.5 y: -0.5z: -0.5
02:12:49: ______________________________________________
02:12:49: pt[1]: x: 0.5 y: -0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[2]: x: -0.5 y: -0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[3]: x: -0.5 y: -0.5z: -0.5
02:12:49: ______________________________________________
02:12:49: pt[4]: x: 0.5 y: 0.5z: -0.499999
02:12:49: ______________________________________________
02:12:49: pt[5]: x: -0.5 y: 0.5z: -0.5
02:12:49: ______________________________________________
02:12:49: pt[6]: x: -0.5 y: 0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[7]: x: 0.499999 y: 0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[8]: x: 0.5 y: -0.5z: -0.5
02:12:49: ______________________________________________
02:12:49: pt[9]: x: 0.5 y: 0.5z: -0.499999
02:12:49: ______________________________________________
02:12:49: pt[10]: x: 0.499999 y: 0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[11]: x: 0.5 y: -0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[12]: x: 0.5 y: -0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[13]: x: 0.499999 y: 0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[14]: x: -0.5 y: 0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[15]: x: -0.5 y: -0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[16]: x: -0.5 y: -0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[17]: x: -0.5 y: 0.5z: 0.494248
02:12:49: ______________________________________________
02:12:49: pt[18]: x: -0.5 y: 0.5z: -0.5
02:12:49: ______________________________________________
02:12:49: pt[19]: x: -0.5 y: -0.5z: -0.5
02:12:49: ______________________________________________
02:12:49: pt[20]: x: 0.5 y: 0.5z: -0.499999
02:12:49: ______________________________________________
02:12:49: pt[21]: x: 0.5 y: -0.5z: -0.5
02:12:49: ______________________________________________
02:12:49: pt[22]: x: -0.5 y: -0.5z: -0.5
02:12:49: ______________________________________________
02:12:49: pt[23]: x: -0.5 y: 0.5z: -0.5
02:12:49: ______________________________________________
02:12:49: vertex_count: 24
02:12:49: after _setcollisionshape mass: 1 - localinertiax: 0
02:12:49: shapetype: 4
I use Visual studio 2017 with Ogre 1.9 and the Bulletphysics version is 2.83.7