Get rid of c++ in blenkernel and modifiers
[blender.git] / source / gameengine / Ketsji / KX_NavMeshObject.cpp
index f72c98fb4bfe6955a99aad514aa29e900372e9e4..5747d8641d01273e986e8dd569b61216926d375f 100644 (file)
@@ -26,6 +26,8 @@
 * ***** END GPL LICENSE BLOCK *****
 */
 
+#include "MEM_guardedalloc.h"
+
 #include "BLI_math_vector.h"
 #include "KX_NavMeshObject.h"
 #include "RAS_MeshObject.h"
@@ -117,8 +119,12 @@ bool KX_NavMeshObject::BuildVertIndArrays(float *&vertices, int& nverts,
                int *dtrisToPolysMap=NULL, *dtrisToTrisMap=NULL, *trisToFacesMap=NULL;
                int nAllVerts = 0;
                float *allVerts = NULL;
-               buildNavMeshDataByDerivedMesh(dm, vertsPerPoly, nAllVerts, allVerts, ndtris, dtris,
-                       npolys, dmeshes, polys, dtrisToPolysMap, dtrisToTrisMap, trisToFacesMap);
+               buildNavMeshDataByDerivedMesh(dm, &vertsPerPoly, &nAllVerts, &allVerts, &ndtris, &dtris,
+                       &npolys, &dmeshes, &polys, &dtrisToPolysMap, &dtrisToTrisMap, &trisToFacesMap);
+
+               MEM_freeN(dtrisToPolysMap);
+               MEM_freeN(dtrisToTrisMap);
+               MEM_freeN(trisToFacesMap);
 
                unsigned short *verticesMap = new unsigned short[nAllVerts];
                memset(verticesMap, 0xffff, sizeof(unsigned short)*nAllVerts);
@@ -207,6 +213,8 @@ bool KX_NavMeshObject::BuildVertIndArrays(float *&vertices, int& nverts,
                                }                               
                        }
                }
+
+               MEM_freeN(allVerts);
        }
        else
        {
@@ -445,7 +453,12 @@ bool KX_NavMeshObject::BuildNavMesh()
        m_navMesh->init(data, dataSize, true);  
 
        delete [] vertices;
-       delete [] polys;
+
+       /* navmesh conversion is using C guarded alloc for memory allocaitons */
+       MEM_freeN(polys);
+       if (dmeshes) MEM_freeN(dmeshes);
+       if (dtris) MEM_freeN(dtris);
+
        if (dvertices)
        {
                delete [] dvertices;