Fix T59925: Crash when adding any generative modifier on a curve with more than one...
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 3 Jan 2019 17:01:56 +0000 (18:01 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 3 Jan 2019 17:09:39 +0000 (18:09 +0100)
Am not totally convinced that generating meshes without fully valid
material info is a good thing, but this seems to be rather common in our
code base (in both mesh editing and convert-to-mesh cases).

So for now, duplicated code in mesh eval finalization to main displist
creation/eval function, synchronizing mat data at the end of modifiers
stack eval, if needed.

source/blender/blenkernel/intern/displist.c

index c5dadb1b52919898405550c57bd7b9b5ce2214da..c5c503966c40c5246a4eaedea9616f91b7d20829 100644 (file)
@@ -1089,12 +1089,22 @@ static void curve_calc_modifiers_post(
                        /* XXX2.8(Sybren): make sure the face normals are recalculated as well */
                        BKE_mesh_ensure_normals(modified);
 
+                       /* Special tweaks, needed since neither BKE_mesh_new_nomain_from_template() nor
+                        * BKE_mesh_new_nomain_from_curve_displist() properly duplicate mat info...
+                        */
+                       BLI_strncpy(modified->id.name, cu->id.name, sizeof(modified->id.name));
+                       *((short *)modified->id.name) = ID_ME;
+                       MEM_SAFE_FREE(modified->mat);
+                       /* Set flag which makes it easier to see what's going on in a debugger. */
+                       modified->id.tag |= LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT;
+                       modified->mat = MEM_dupallocN(cu->mat);
+                       modified->totcol = cu->totcol;
+
                        (*r_final) = modified;
                }
                else {
                        (*r_final) = NULL;
                }
-
        }
 }