Mesh shape generation causing odd error.

Mesh shape generation causing odd error.

Whenever I create a triangle mesh shape with a certain mesh, it will throw out "t:BuildcodePcXs0SourceCommon/Base/Math/Vector/hkVector4Util.inl<119> [0x4868f301 ] Assert : 'aabb.isValid()
Aabb at 0020E780 was invalid. (Contains a NaN or min > max)'

My code for generating my triangle meshes is below. If anyone could offer up a better way of doing this please do, as I fear I am doing them completely wrong...

hkpRigidBody* createTriangleMesh(hkpWorld* pWorld, irr::scene::IAnimatedMesh* mesh)
hkpExtendedMeshShape* meshShape = new hkpExtendedMeshShape(0.0f);

for (irr::u32 i = 0; i < mesh->getMeshBufferCount(); i++)
irr::scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);

irr::video::S3DVertex* vertices = (irr::video::S3DVertex*)mb->getVertices();

irr::f32* vertexBuffer = new irr::f32[mb->getVertexCount() * 3];
irr::u16* indexBuffer = new irr::u16[mb->getIndexCount()];

int tmpCounter = 0;

for (irr::u32 x = 0; x < mb->getVertexCount(); x++)
vertexBuffer[tmpCounter] = vertices[x].Pos.X;
vertexBuffer[tmpCounter+1] = vertices[x].Pos.Y;
vertexBuffer[tmpCounter+2] = vertices[x].Pos.Z;

tmpCounter += 3;

indexBuffer = mb->getIndices();

hkpExtendedMeshShape::TrianglesSubpart part;

part.m_vertexBase = vertexBuffer;
part.m_vertexStriding = sizeof(float) * 3;
part.m_numVertices = mb->getVertexCount();

part.m_indexBase = indexBuffer;
part.m_indexStriding = sizeof(unsigned short)*3;
part.m_numTriangleShapes = mb->getIndexCount()/3;
part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;

amp;nbsp; }

hkpRigidBodyCinfo info;

info.m_shape = meshShape;
info.m_motionType = hkpMotion::MOTION_FIXED;

hkpRigidBody* r = new hkpRigidBody(info);


return r;

Also, forgive me if those code brackets didn't work, as I am aware how ugly code can be when not formatted correctly...

7 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Ok, clearly that code came up terribly. Sorry about that. Here is my code on pastebin:

Hi benny,

I'm not sure if it's the main problem or not, but you've got

irr::u16* indexBuffer = new irr::u16[mb->getIndexCount()];
indexBuffer = mb->getIndices();

At best, that's a memory leak :) Do you mean to copy the indices like you do with the vertices? If mb's indices get deleted/freed somewhere else, then that pointer will be garbage and could definitely cause the assert you're seeing - bad indices will cause Havok to read bad vertices, and bad vertices lead to bad AABBs.


I don't believe that mb's indices are getting deleted anywhere. And that wasn't the main problem, but thanks for pointing that out ^^

Doh, so much for the easy answer.

Can you cook up a simple example (e.g. a cube or tetrahedron) that fails, look at the contents of the index and vertex arrays, and paste them here? In Visual Studio, at a breakpoint, you can do this by going to the watch window and entering "indexBuffer, 12" and it will show you the first 12 values in the array. Obviously the number will depend on the size of your array; that's why you want to keep the example small.

Also, what's the callstack when you hit the assert?


Ah, debugging revealed that it might not be a problem with Havok. Its looking like its Irrlicht's fault. The call to mesh->getMeshBufferCount() returns 0, so it doesn't go through the loop and tries to initialize a blank hkpExtendedMeshShape. I assume thats why it throws the exception.

Yeah, that would do it :)

If you're still having problems after you get that fixed, let me know...

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui