Maniphest T48992

Unicode strings in ID properties cause UI glitch
Closed, Duplicate

Assigned To
None
Authored By
Sybren A. Stüvel (sybren)
Aug 1 2016, 3:30 PM
Tags
  • BF Blender
Subscribers
Brecht Van Lommel (brecht)
Sybren A. Stüvel (sybren)

Description

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

  1. Grab this blend file
  2. Ensure the default cube is still selected, and run the script
  3. Scroll down the object properties panel, and open the "String bug panel"
  4. 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.

Related Objects

Mentioned In
rBCA2c70ceb48959: Solved issue T48992
Mentioned Here
T48873: EnumProperty using update function and expand option is not correctly drawing
rB7065022f7aa2: Fix T48901: Blender ignores xinput cursor matrix

Event Timeline

Sybren A. Stüvel (sybren) created this task.Aug 1 2016, 3:30 PM
Sybren A. Stüvel (sybren) updated the task description.Aug 1 2016, 4:04 PM
Brecht Van Lommel (brecht) added a subscriber: Brecht Van Lommel (brecht).Aug 2 2016, 12:45 AM

I suspect it's the same as issue as T48873.

Sybren A. Stüvel (sybren) mentioned this in rBCA2c70ceb48959: Solved issue T48992.Aug 30 2016, 4:47 PM