blender-cod icon indicating copy to clipboard operation
blender-cod copied to clipboard

Mesh cannot be removed from main database

Open BTOdell opened this issue 2 years ago • 0 comments

Python: Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_cod\__init__.py", line 610, in execute
    result = export_xmodel.save(self, context,
  File "C:\Users\xxx\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_cod\export_xmodel.py", line 394, in save
    result = save_model(self, context, filepath,
  File "C:\Users\xxx\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_cod\export_xmodel.py", line 602, in save_model
    mesh.clear()
  File "C:\Users\xxx\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\io_scene_cod\export_xmodel.py", line 205, in clear
    bpy.data.meshes.remove(self.mesh)
RuntimeError: Error: Mesh 'MyMesh' is outside of main database and can not be removed from it

I believe this is due to the new way that a mesh is generated from objects:

depsgraph = context.evaluated_depsgraph_get()
mesh = ob.evaluated_get(depsgraph).to_mesh()

According to the documentation of to_mesh():

Create a Mesh data-block from the current state of the object.
The object owns the data-block. To force free it use to_mesh_clear().
The result is temporary and can not be used by objects from the main database.

BTOdell avatar Jan 26 '22 02:01 BTOdell