Fix T38941: Laplacian Deform crashes on OSX
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 4 Mar 2014 08:09:38 +0000 (09:09 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 4 Mar 2014 08:09:38 +0000 (09:09 +0100)
When vgroup was invalid somehow (e.g. empty, as in this case) and bind could not happen, code was dereferencing a NULL pointer...

source/blender/modifiers/intern/MOD_laplaciandeform.c

index fa56698e1dc8586741889b6172e20f977434d242..9ed99fc4aedab6c85b4923159f09b49bb3b95358 100644 (file)
@@ -755,27 +755,27 @@ static void LaplacianDeformModifier_do(
                }
        }
        else {
-               if (lmd->total_verts > 0 && lmd->total_verts == numVerts) {
-                       if (isValidVertexGroup(lmd, ob, dm)) {
-                               filevertexCos = MEM_mallocN(sizeof(float[3]) * numVerts, "TempDeformCoordinates");
-                               memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * numVerts);
-                               MEM_SAFE_FREE(lmd->vertexco);
-                               lmd->total_verts = 0;
-                               initSystem(lmd, ob, dm, filevertexCos, numVerts);
-                               sys = lmd->cache_system;
-                               MEM_SAFE_FREE(filevertexCos);
-                               laplacianDeformPreview(sys, vertexCos);
-                       }
+               if (!isValidVertexGroup(lmd, ob, dm)) {
+                       modifier_setError(&lmd->modifier, "Vertex group '%s' is not valid", lmd->anchor_grp_name);
+                       lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND;
+               }
+               else if (lmd->total_verts > 0 && lmd->total_verts == numVerts) {
+                       filevertexCos = MEM_mallocN(sizeof(float[3]) * numVerts, "TempDeformCoordinates");
+                       memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * numVerts);
+                       MEM_SAFE_FREE(lmd->vertexco);
+                       lmd->total_verts = 0;
+                       initSystem(lmd, ob, dm, filevertexCos, numVerts);
+                       sys = lmd->cache_system;
+                       MEM_SAFE_FREE(filevertexCos);
+                       laplacianDeformPreview(sys, vertexCos);
                }
                else {
-                       if (isValidVertexGroup(lmd, ob, dm)) {
-                               initSystem(lmd, ob, dm, vertexCos, numVerts);
-                               sys = lmd->cache_system;
-                               laplacianDeformPreview(sys, vertexCos);
-                       }
+                       initSystem(lmd, ob, dm, vertexCos, numVerts);
+                       sys = lmd->cache_system;
+                       laplacianDeformPreview(sys, vertexCos);
                }
        }
-       if (sys->is_matrix_computed && !sys->has_solution) {
+       if (sys && sys->is_matrix_computed && !sys->has_solution) {
                modifier_setError(&lmd->modifier, "The system did not find a solution");
        }
 }