System Information
Kubuntu 16.04
Blender Version
Broken: 2.70a, 2.77a and 7065022f7aa (2.65a also fails, but just shows an empty value)
Worked: 2.60a
Short description of error
When an EnumProperty gets its values from a function, which uses an Unicode string from an ID property, the UI gets corrupted.
Exact steps for others to reproduce the error
- Grab this blend file
- Ensure the default cube is still selected, and run the script
- Scroll down the object properties panel, and open the "String bug panel"
- Move your mouse to trigger UI updates, and see the value flicker between different invalid strings.
This is the code from the blend file that triggers this error:
import bpy # Run this script with the default cube selected. bpy.context.object['id_value'] = '½k' def get_items(self, context): # These values are the same in Python, but are handled differently # by Blender. assert self['id_value'] == '½k' return [ ('buggy_key', self['id_value'], 'This value is very buggy in the GUI'), ('okay_key', '½k', 'This value is just fine'), ] bpy.types.Object.buggy_prop = bpy.props.EnumProperty( items=get_items) class StringBugPanel(bpy.types.Panel): bl_label = "String bug panel" bl_idname = "OBJECT_PT_hello" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "object" def draw(self, context): self.layout.prop(context.object, "buggy_prop") def register(): bpy.utils.register_class(StringBugPanel) def unregister(): bpy.utils.unregister_class(StringBugPanel) if __name__ == "__main__": register()
As you can see, the bug doesn't manifest itself when the string is a pure Python string (the 'okay_key' value). However, it fails if it is stored in an ID property, even though the two are considered equal in the Python domain.
Update: I've tested to create a copy of the string, using self['id_value'][:] and str(self['id_value']), but that also gets corrupted. Concatenating with 'xx' + self['id_value'] also gets corrupted.
