[Bf-blender-cvs] [72a563cdee8] master: Fix bmesh_to_mesh freeing possibly referenced vertices

Sergey Sharybin noreply at git.blender.org
Fri May 31 15:07:18 CEST 2019


Commit: 72a563cdee8fef198a200ff65b57ddb847c01795
Author: Sergey Sharybin
Date:   Fri May 31 15:06:01 2019 +0200
Branches: master
https://developer.blender.org/rB72a563cdee8fef198a200ff65b57ddb847c01795

Fix bmesh_to_mesh freeing possibly referenced vertices

Fixes Godot exporter issue reported in T65285.

===================================================================

M	source/blender/bmesh/intern/bmesh_mesh_conv.c
M	source/blender/python/bmesh/bmesh_py_types.c

===================================================================

diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c
index 0ea33049458..7a100167b48 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_conv.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c
@@ -611,12 +611,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
 
   /* lets save the old verts just in case we are actually working on
    * a key ... we now do processing of the keys at the end */
-  oldverts = me->mvert;
-
-  /* don't free this yet */
-  if (oldverts) {
-    CustomData_set_layer(&me->vdata, CD_MVERT, NULL);
-  }
+  oldverts = MEM_dupallocN(me->mvert);
 
   /* free custom data */
   CustomData_free(&me->vdata, me->totvert);
@@ -975,7 +970,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
     }
   }
 
-  if (oldverts) {
+  if (oldverts != NULL) {
     MEM_freeN(oldverts);
   }
 
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index eb611e6566a..89d15edb0bd 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -31,6 +31,7 @@
 #include "BKE_customdata.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
+#include "BKE_mesh.h"
 #include "BKE_mesh_runtime.h"
 
 #include "DEG_depsgraph.h"
@@ -1089,13 +1090,19 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args)
 
   bm = self->bm;
 
-  BLI_assert(BKE_id_is_in_global_main(&me->id));
-  BM_mesh_bm_to_me(G_MAIN, /* XXX UGLY! */
-                   bm,
-                   me,
-                   (&(struct BMeshToMeshParams){
-                       .calc_object_remap = true,
-                   }));
+  struct Main *bmain = NULL;
+  struct BMeshToMeshParams params = {0};
+  if (me->id.tag & LIB_TAG_NO_MAIN) {
+    /* Mesh might be coming from a self-contained source like object.to_mesh(). No need to remap
+     * anything in this case. */
+  }
+  else {
+    BLI_assert(BKE_id_is_in_global_main(&me->id));
+    bmain = G_MAIN; /* XXX UGLY! */
+    params.calc_object_remap = true;
+  }
+
+  BM_mesh_bm_to_me(bmain, bm, me, &params);
 
   /* we could have the user do this but if they forget blender can easy crash
    * since the references arrays for the objects derived meshes are now invalid */



More information about the Bf-blender-cvs mailing list