diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2019-08-16 15:36:57 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2019-08-16 15:36:57 +0300 |
commit | c70f975d5c3b961e0c77eba3a35c8a892f39214d (patch) | |
tree | 04dc64117f78b16f9e6aa47f040edfe9ad6677a2 /source/blender/blenkernel | |
parent | 82e719ff8764da6c48ba3de4e5c11226953002e8 (diff) |
Fix T67999: calling Mesh.materials.clear() crashes Blender
The `BKE_material_pop_id()` and `BKE_material_clear_id()` functions had
a parameter `update_data` that, when `false`, would cause the mesh polys
to keep their material index, even when the indexed material slots were
removed. This behaviour was never used in the C code and not supported
by the drawing code, making polygons disappear and causing crashes. The
Python binding in RNA, however, defaulted to `update_data=False`.
This commit removes the `update_data` parameter altogether, and makes
the functions always fix up the material indices.
Reviewed by: mont29, brecht
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_material.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 16 |
2 files changed, 7 insertions, 14 deletions
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 5bb69c7166e..44a8f98e994 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -104,9 +104,8 @@ void BKE_material_append_id(struct Main *bmain, struct ID *id, struct Material * struct Material *BKE_material_pop_id(struct Main *bmain, struct ID *id, /* index is an int because of RNA. */ - int index, - bool update_data); -void BKE_material_clear_id(struct Main *bmain, struct ID *id, bool update_data); + int index); +void BKE_material_clear_id(struct Main *bmain, struct ID *id); /* rendering */ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]); diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index b01c1189fd1..1545ae4f48f 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -461,7 +461,7 @@ void BKE_material_append_id(Main *bmain, ID *id, Material *ma) } } -Material *BKE_material_pop_id(Main *bmain, ID *id, int index_i, bool update_data) +Material *BKE_material_pop_id(Main *bmain, ID *id, int index_i) { short index = (short)index_i; Material *ret = NULL; @@ -489,10 +489,7 @@ Material *BKE_material_pop_id(Main *bmain, ID *id, int index_i, bool update_data test_all_objects_materials(bmain, id); } - if (update_data) { - /* decrease mat_nr index */ - material_data_index_remove_id(id, index); - } + material_data_index_remove_id(id, index); DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE); DEG_relations_tag_update(bmain); @@ -502,7 +499,7 @@ Material *BKE_material_pop_id(Main *bmain, ID *id, int index_i, bool update_data return ret; } -void BKE_material_clear_id(Main *bmain, ID *id, bool update_data) +void BKE_material_clear_id(Main *bmain, ID *id) { Material ***matar; if ((matar = give_matarar_id(id))) { @@ -516,12 +513,9 @@ void BKE_material_clear_id(Main *bmain, ID *id, bool update_data) MEM_freeN(*matar); *matar = NULL; } - test_all_objects_materials(bmain, id); - if (update_data) { - /* decrease mat_nr index */ - material_data_index_clear_id(id); - } + test_all_objects_materials(bmain, id); + material_data_index_clear_id(id); DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE); DEG_relations_tag_update(bmain); |