Creating hkpSimpleMeshShape crash.

Creating hkpSimpleMeshShape crash.

Hello, I'm trying to import .obj files into my physics world, so I decided to make a converter that would convert read them and make ahkpBvTreeShape from the data. I'm trying to this like so:I've made a MeshData struct which holds the information of the mesh, and it's structured like this:

struct MeshData


	MeshData(std::vector iVertices, std::vector iFaces, int iFaceNum, int iVertNum)


		vertices = iVertices;

		faces = iFaces;

		numFaces = iFaceNum;

		numVerts = iVertNum;

	int numVerts;

	int numFaces;

	std::vector vertices;

	std::vector faces;


And I'm reading the data and with a function called getMeshData() which returns a MeshData object which is filled with the data from the file. (I'm not going to post it here, but basically you just tokenize and parse the vertices and faces, and then put them into a Vector3 (for the vertices) and Vector4 (for the faces)).But here's how I'm trying to convert the data into a Havok shape:
static void processFile(std::string file)


	MeshData data = getMeshData(file);

	float radius = -1.0f;

	std::cout << "HERE ?n";

	// Crash after the above line.

	hkpSimpleMeshShape* meshStorage = new hkpSimpleMeshShape(hkConvexShapeDefaultRadius);

	std::cout << "HERE2 ?n";


	for(int i = 0; i < data.numVerts; i++){

		hkVector4 vertex(data.vertices[i].x, data.vertices[i].y, data.vertices[i].z);

		meshStorage->m_vertices[i] = vertex;


	for(int i = 0; i < data.numFaces; i++){

		meshStorage->m_triangles[i].m_a = data.faces[i].x-1;

		meshStorage->m_triangles[i].m_b = data.faces[i].y-1;

		meshStorage->m_triangles[i].m_c = data.faces[i].z-1;

	hkpMoppCompilerInput mfr;

	mfr.setAbsoluteFitToleranceOfAxisAlignedTriangles( hkVector4( 0.1f, 0.1f, 0.1f ) );

	hkpMoppCode* pCode = hkpMoppUtility::buildCode( meshStorage, mfr );

	hkpBvTreeShape* shape = new hkpMoppBvTreeShape( meshStorage, pCode );


The first thing that came to mind when I thought of what could be causing the crash is not creating the physics world (or anything else for that matter) before doing this, but I still don't know what exactly it is.I will debug it later and see if I can find something more.The output from this:
	for (int i = 0; i < data.vertices.size(); i++)

		std::cout << "Vertex " << i << ": " << data.vertices[i] << std::endl;

	for (int i = 0; i < data.faces.size(); i++)

		std::cout << "Face " << i << ": " << data.faces[i] << std::endl;
is this (actually the following is the output from the whole program):
OgreToHavok.exeloaded 8 verticesloaded 6 facesVertex 0: Vector3(1, -1, -1)Vertex 1: Vector3(1, -1, 1)Vertex 2: Vector3(-1, -1, 1)Vertex 3: Vector3(-1, -1, -1)Vertex 4: Vector3(1, 1, -0.999999)Vertex 5: Vector3(0.999999, 1, 1)Vertex 6: Vector3(-1, 1, 1)Vertex 7: Vector3(-1, 1, -1)Face 0: Vector4(1, 2, 3, 4)Face 1: Vector4(5, 8, 7, 6)Face 2: Vector4(1, 5, 6, 2)Face 3: Vector4(2, 6, 7, 3)Face 4: Vector4(3, 7, 8, 4)Face 5: Vector4(5, 1, 4, 8)HERE ?

And here's the file I'm testing this on (though it doesn't really matter now since I'm not actually utilizing the data yet because the crash happens before it can do that.

2 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

OK, after finally building it and running it in debug, I managed to find out that you need to initialize.Just in case anyone needs it, now I have:

	// Base havok init:
	hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault( hkMallocAllocator::m_defaultMallocAllocator, hkMemorySystem::FrameInfo( 500* 1024 ) );

	hkBaseSystem::init( memoryRouter, errorReport );


Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen