Fix T59990: Crash when entering edit mode with skin modifier enabled
authorClément Foucault <foucault.clem@gmail.com>
Fri, 11 Jan 2019 16:21:22 +0000 (17:21 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Fri, 11 Jan 2019 17:56:05 +0000 (18:56 +0100)
The skin modifier does not keep the UV layers.

This just add a safety check when there is no UV layers.

source/blender/draw/intern/draw_cache_impl_mesh.c

index 92131a2e74c2caed92167b77b54b473c8676ddde..5ed1bcb2f43fe4752218efcdbcacbccb2437cb09 100644 (file)
@@ -868,9 +868,9 @@ static MeshRenderData *mesh_render_data_create_ex(
                        .vcol_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPCOL),
                };
 
-               rdata->cd.layers.uv_len = count_bits_i(cd_lused[CD_MLOOPUV]);
+               rdata->cd.layers.uv_len = min_ii(cd_layers_src.uv_len, count_bits_i(cd_lused[CD_MLOOPUV]));
                rdata->cd.layers.tangent_len = count_bits_i(cd_lused[CD_TANGENT]);
-               rdata->cd.layers.vcol_len = count_bits_i(cd_lused[CD_MLOOPCOL]);
+               rdata->cd.layers.vcol_len = min_ii(cd_layers_src.vcol_len, count_bits_i(cd_lused[CD_MLOOPCOL]));
 
                rdata->cd.layers.uv = MEM_mallocN(sizeof(*rdata->cd.layers.uv) * rdata->cd.layers.uv_len, __func__);
                rdata->cd.layers.vcol = MEM_mallocN(sizeof(*rdata->cd.layers.vcol) * rdata->cd.layers.vcol_len, __func__);
@@ -3139,6 +3139,11 @@ static void mesh_create_loop_uv_and_tan(MeshRenderData *rdata, GPUVertBuf *vbo)
                }
        }
 
+       /* HACK: Create a dummy attrib in case there is no valid UV/tangent layer. */
+       if (layers_combined_len == 0) {
+               GPU_vertformat_attr_add(&format, "dummy", GPU_COMP_U8, 1, GPU_FETCH_INT_TO_FLOAT_UNIT);
+       }
+
        GPU_vertbuf_init_with_format(vbo, &format);
        GPU_vertbuf_data_alloc(vbo, loops_len);