diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-12-18 22:51:32 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-12-18 22:51:52 +0300 |
commit | 5e4677c9621de34d8dce65e3fb74a71da831ad7f (patch) | |
tree | fe630f68b554371575a9baeb89df943a3d73c57e /source/blender | |
parent | 604101d2620626c1ad95e1271b6616a339dbe9b8 (diff) |
Workbench: Fix crash when sculpting with a multi material mesh
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/engines/workbench/workbench_deferred.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c index 617108b1bde..66a98ef2e00 100644 --- a/source/blender/draw/engines/workbench/workbench_deferred.c +++ b/source/blender/draw/engines/workbench/workbench_deferred.c @@ -821,7 +821,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) if (!is_sculpt_mode && TEXTURE_DRAWING_ENABLED(wpd) && ELEM(ob->type, OB_MESH)) { const Mesh *me = ob->data; if (me->mloopuv) { - const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol)); + const int materials_len = ob->totcol; struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob); for (int i = 0; i < materials_len; i++) { Material *mat = give_current_material(ob, i + 1); @@ -851,27 +851,29 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) } } else { /* MATERIAL colors */ - const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol)); - struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len); - for (int i = 0; i < materials_len; i++) { - gpumat_array[i] = NULL; + if (is_sculpt_mode) { + /* Multiple materials are not supported in sculpt mode yet. */ + Material *mat = give_current_material(ob, 1); + material = get_or_create_material_data(vedata, ob, mat, NULL, V3D_SHADING_MATERIAL_COLOR); + DRW_shgroup_call_sculpt_add(material->shgrp, ob, ob->obmat); } + else { + struct GPUBatch **geoms; + const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol)); + struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len); + for (int i = 0; i < materials_len; i++) { + gpumat_array[i] = NULL; + } + geoms = DRW_cache_object_surface_material_get(ob, gpumat_array, materials_len, NULL, NULL, NULL); - struct GPUBatch **mat_geom = DRW_cache_object_surface_material_get( - ob, gpumat_array, materials_len, NULL, NULL, NULL); - if (mat_geom) { - for (int i = 0; i < materials_len; ++i) { - if (mat_geom[i] == NULL) { - continue; - } - - Material *mat = give_current_material(ob, i + 1); - material = get_or_create_material_data(vedata, ob, mat, NULL, V3D_SHADING_MATERIAL_COLOR); - if (is_sculpt_mode) { - DRW_shgroup_call_sculpt_add(material->shgrp, ob, ob->obmat); - } - else { - DRW_shgroup_call_object_add(material->shgrp, mat_geom[i], ob); + if (geoms) { + for (int i = 0; i < materials_len; ++i) { + if (geoms[i] == NULL) { + continue; + } + Material *mat = give_current_material(ob, i + 1); + material = get_or_create_material_data(vedata, ob, mat, NULL, V3D_SHADING_MATERIAL_COLOR); + DRW_shgroup_call_object_add(material->shgrp, geoms[i], ob); } } } |