Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-06-26 08:17:41 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-06-26 08:17:41 +0400
commitc0c9f5386bac539e3824a5a97bd2243484598594 (patch)
treee1b40ad75e51f7c76707b7506312a11339742f4e /source/blender/bmesh/intern/bmesh_mesh_conv.c
parent7d608452d0c10da9b71ca37cb3bdbdfe0e5ebe36 (diff)
fix [#35507] BMesh module: Crash on to_mesh() if faces.layers.tex is used but no loops.layers.uv
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_mesh_conv.c')
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh_conv.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c
index 9d330075a3a..7c4af8eaa3b 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_conv.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c
@@ -98,6 +98,42 @@
#include "bmesh.h"
#include "intern/bmesh_private.h" /* for element checking */
+/**
+ * Currently this is only used for Python scripts
+ * which may fail to keep matching UV/TexFace layers.
+ *
+ * \note This should only perform any changes in exceptional cases,
+ * if we need this to be faster we could inline #BM_data_layer_add and only
+ * call #update_data_blocks once at the end.
+ */
+void BM_mesh_cd_validate(BMesh *bm)
+{
+ int totlayer_mtex = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
+ int totlayer_uv = CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV);
+
+ if (LIKELY(totlayer_mtex == totlayer_uv)) {
+ /* pass */
+ }
+ else if (totlayer_mtex < totlayer_uv) {
+ const int uv_index_first = CustomData_get_layer_index(&bm->ldata, CD_MLOOPUV);
+ do {
+ const char *from_name = bm->ldata.layers[uv_index_first + totlayer_mtex].name;
+ BM_data_layer_add_named(bm, &bm->pdata, CD_MTEXPOLY, from_name);
+ CustomData_set_layer_unique_name(&bm->pdata, totlayer_mtex);
+ } while (totlayer_uv != ++totlayer_mtex);
+ }
+ else if (totlayer_uv < totlayer_mtex) {
+ const int mtex_index_first = CustomData_get_layer_index(&bm->pdata, CD_MTEXPOLY);
+ do {
+ const char *from_name = bm->pdata.layers[mtex_index_first + totlayer_uv].name;
+ BM_data_layer_add_named(bm, &bm->ldata, CD_MLOOPUV, from_name);
+ CustomData_set_layer_unique_name(&bm->ldata, totlayer_uv);
+ } while (totlayer_mtex != ++totlayer_uv);
+ }
+
+ BLI_assert(totlayer_mtex == totlayer_uv);
+}
+
void BM_mesh_cd_flag_ensure(BMesh *bm, Mesh *mesh, const char cd_flag)
{
const char cd_flag_all = BM_mesh_cd_flag_from_bmesh(bm) | cd_flag;