浏览代码

fix 'struct rna of ExportGodot removed' error (#393)

* fix 'struct rna of ExportGodot removed' error if upexpected error occured while exporting

* Update __init__.py

* Update __init__.py

* Update __init__.py

Co-authored-by: U-TTE\celpec <[email protected]>
Celpec 4 年之前
父节点
当前提交
aba3cfaf3f
共有 2 个文件被更改,包括 6 次插入5 次删除
  1. 6 1
      io_scene_godot/__init__.py
  2. 0 4
      io_scene_godot/export_godot.py

+ 6 - 1
io_scene_godot/__init__.py

@@ -19,6 +19,7 @@ without significant importing (it's the same as Godot's tscn format).
 #
 #
 # ##### END GPL LICENSE BLOCK #####
 # ##### END GPL LICENSE BLOCK #####
 
 
+import logging
 import bpy
 import bpy
 from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty
 from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty
 from bpy_extras.io_utils import ExportHelper
 from bpy_extras.io_utils import ExportHelper
@@ -206,6 +207,7 @@ class ExportGodot(bpy.types.Operator, ExportHelper):
 
 
     def execute(self, context):
     def execute(self, context):
         """Begin the export"""
         """Begin the export"""
+        exporter_log_handler = export_godot.ExporterLogHandler(self)
         try:
         try:
             if not self.filepath:
             if not self.filepath:
                 raise Exception("filepath not set")
                 raise Exception("filepath not set")
@@ -218,11 +220,14 @@ class ExportGodot(bpy.types.Operator, ExportHelper):
                 "filter_glob",
                 "filter_glob",
                 "xna_validate",
                 "xna_validate",
             ))
             ))
-
+            logging.getLogger().addHandler(exporter_log_handler)
             return export_godot.save(self, context, **keywords)
             return export_godot.save(self, context, **keywords)
         except ValidationError as error:
         except ValidationError as error:
             self.report({'ERROR'}, str(error))
             self.report({'ERROR'}, str(error))
             return {'CANCELLED'}
             return {'CANCELLED'}
+        finally:
+            if exporter_log_handler:
+                logging.getLogger().removeHandler(exporter_log_handler)
 
 
 
 
 def menu_func(self, context):
 def menu_func(self, context):

+ 0 - 4
io_scene_godot/export_godot.py

@@ -313,8 +313,6 @@ class GodotExporter:
 
 
 def save(operator, context, filepath="", **kwargs):
 def save(operator, context, filepath="", **kwargs):
     """Begin the export"""
     """Begin the export"""
-    exporter_log_handler = ExporterLogHandler(operator)
-    logging.getLogger().addHandler(exporter_log_handler)
 
 
     object_types = kwargs["object_types"]
     object_types = kwargs["object_types"]
     # GEOMETRY isn't an object type so replace it with all valid geometry based
     # GEOMETRY isn't an object type so replace it with all valid geometry based
@@ -326,6 +324,4 @@ def save(operator, context, filepath="", **kwargs):
     with GodotExporter(filepath, kwargs, operator) as exp:
     with GodotExporter(filepath, kwargs, operator) as exp:
         exp.export()
         exp.export()
 
 
-    logging.getLogger().removeHandler(exporter_log_handler)
-
     return {"FINISHED"}
     return {"FINISHED"}