create navmesh operator would crash on non-mesh objects, add type check and report...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 10 Oct 2011 22:06:07 +0000 (22:06 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 10 Oct 2011 22:06:07 +0000 (22:06 +0000)
source/blender/editors/mesh/mesh_navmesh.c

index 4ae1cdeed0233501b1904a5e5e47f657ecda8368..bd5f4b5fe68ba186b386b082f86c0fae0c13c17c 100644 (file)
@@ -424,34 +424,45 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh,
        return obedit;
 }
 
-static int create_navmesh_exec(bContext *C, wmOperator *UNUSED(op))
+static int create_navmesh_exec(bContext *C, wmOperator *op)
 {
        Scene* scene= CTX_data_scene(C);
-       int nverts= 0, ntris= 0;
-       float *verts= NULL;
-       int *tris= 0;
-       struct recast_polyMesh *pmesh= NULL;
-       struct recast_polyMeshDetail *dmesh= NULL;
        LinkNode* obs= NULL;
        Base* navmeshBase= NULL;
 
        CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
-               if(base->object->body_type==OB_BODY_TYPE_NAVMESH) {
-                       if(!navmeshBase || base == scene->basact)
-                               navmeshBase= base;
+               if (base->object->type == OB_MESH) {
+                       if (base->object->body_type==OB_BODY_TYPE_NAVMESH) {
+                               if (!navmeshBase || base == scene->basact) {
+                                       navmeshBase= base;
+                               }
+                       }
+                       else {
+                               BLI_linklist_append(&obs, (void*)base->object);
+                       }
                }
-               else
-                       BLI_linklist_append(&obs, (void*)base->object);
        }
        CTX_DATA_END;
 
-       createVertsTrisData(C, obs, &nverts, &verts, &ntris, &tris);
-       BLI_linklist_free(obs, NULL);
-       buildNavMesh(&scene->gm.recastData, nverts, verts, ntris, tris, &pmesh, &dmesh);
-       createRepresentation(C, pmesh, dmesh, navmeshBase);
+       if (obs) {
+               struct recast_polyMesh *pmesh= NULL;
+               struct recast_polyMeshDetail *dmesh= NULL;
+
+               int nverts= 0, ntris= 0;
+               int *tris= 0;
+               float *verts= NULL;
 
-       MEM_freeN(verts);
-       MEM_freeN(tris);
+               createVertsTrisData(C, obs, &nverts, &verts, &ntris, &tris);
+               BLI_linklist_free(obs, NULL);
+               buildNavMesh(&scene->gm.recastData, nverts, verts, ntris, tris, &pmesh, &dmesh);
+               createRepresentation(C, pmesh, dmesh, navmeshBase);
+
+               MEM_freeN(verts);
+               MEM_freeN(tris);
+       }
+       else {
+               BKE_report(op->reports, RPT_ERROR, "No mesh objects found");
+       }
 
        return OPERATOR_FINISHED;
 }