Skip to content

Commit 8765f76

Browse files
authored
Merge pull request #12 from drichardson/utf8-decode-error
keep python reference to dynamically generated EnumProperty items
2 parents 551e573 + 4575c50 commit 8765f76

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

__init__.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
# MMT stands for Mr Mannequins Tools, E stands for export, I stands for import, S stands for Stash, L stands for Load, A stands for Add, O stands for option...
6767
# and JK/Jk/jk stands for Jim Kroovy and is the creator prefix i use for anything that might be used elsewhere... (makes for easier searching in most editing programs)
6868

69+
# Dynamically generated EnumProperty items must be referenced from Python!!!
70+
# You must maintain a reference to dynamically generated EnumProperty items from Python or else Blender
71+
# will not behave properly (symptomps are garbage strings, utf-8 decode errors, and crashes). For more information, see:
72+
# https://docs.blender.org/api/current/bpy.props.html?highlight=bpy%20props%20enumproperty#bpy.props.EnumProperty
73+
# https://developer.blender.org/T50426
74+
6975
#---------- FUNCTIONS --------------------------------------------------------------------------
7076

7177
# one little message box function... (just in case)
@@ -103,6 +109,9 @@ def Get_Stashed_MMT(MMT_path, armature, S_path, type):
103109
return items
104110

105111
# gets all the saved stash paths from add-on preferences...
112+
113+
Get_Stashes_Result_Reference=[]
114+
106115
def Get_Stashes(self, context):
107116
stashes = []
108117
prefs = bpy.context.preferences.addons["MrMannequinsTools"].preferences
@@ -112,6 +121,12 @@ def Get_Stashes(self, context):
112121
stashes.append(stash)
113122
else:
114123
prefs.S_paths.remove(stash)
124+
125+
# There is a known bug with using a callback, Python must keep a reference to the strings returned by the callback or Blender will misbehave or even crash.
126+
# https://docs.blender.org/api/current/bpy.props.html?highlight=bpy%20props%20enumproperty#bpy.props.EnumProperty
127+
global Get_Stashes_Result_Reference
128+
Get_Stashes_Result_Reference=stashes
129+
115130
if len(stashes) > 0:
116131
return stashes
117132
else:
@@ -198,20 +213,39 @@ def draw(self, context):
198213
row = layout.row()
199214
row.label(text="See tool panel for options")
200215

216+
# There is a known bug with using a callback, Python must keep a reference to the strings returned by the callback or Blender will misbehave or even crash.
217+
# https://docs.blender.org/api/current/bpy.props.html?highlight=bpy%20props%20enumproperty#bpy.props.EnumProperty
218+
Get_Stashed_Armatures_Results_Reference = []
219+
Get_Stashed_Meshes_Results_Reference = []
220+
Get_Stashed_Materials_Results_Reference = []
221+
Get_Import_Animations_Results_Reference = []
222+
201223
# all the main add-on options...
202224
class JK_MMT_Props(PropertyGroup):
203225

204226
def Get_Stashed_Armatures(self, context):
205-
return Get_Stashed_MMT(self.MMT_path, bpy.context.object, self.S_path, 'ARMATURE')
227+
result = Get_Stashed_MMT(self.MMT_path, bpy.context.object, self.S_path, 'ARMATURE')
228+
global Get_Stashed_Armatures_Results_Reference
229+
Get_Stashed_Armatures_Results_Reference = result
230+
return result
206231

207232
def Get_Stashed_Meshes(self, context):
208-
return Get_Stashed_MMT(self.MMT_path, bpy.context.object, self.S_path, 'MESH')
233+
result = Get_Stashed_MMT(self.MMT_path, bpy.context.object, self.S_path, 'MESH')
234+
global Get_Stashed_Meshes_Results_Reference
235+
Get_Stashed_Meshes_Results_Reference = result
236+
return result
209237

210238
def Get_Stashed_Materials(self, context):
211-
return Get_Stashed_MMT(self.MMT_path, bpy.context.object, self.S_path, 'MATERIAL')
239+
result = Get_Stashed_MMT(self.MMT_path, bpy.context.object, self.S_path, 'MATERIAL')
240+
global Get_Stashed_Materials_Results_Reference
241+
Get_Stashed_Materials_Results_Reference = result
242+
return result
212243

213244
def Get_Import_Animations(self, context):
214-
return Get_Imports_FBX(self, context, self.I_path_animations)
245+
result = Get_Imports_FBX(self, context, self.I_path_animations)
246+
global Get_Import_Animations_Results_Reference
247+
Get_Import_Animations_Results_Reference = result
248+
return result
215249

216250
MMT_path: StringProperty(
217251
name="",

0 commit comments

Comments
 (0)