Fix bmesh_to_mesh freeing possibly referenced vertices
Fixes Godot exporter issue reported in T65285.
This commit is contained in:
		@@ -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, ¶ms);
 | 
			
		||||
 | 
			
		||||
  /* 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 */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user