Log In
New Account
Home My Page Projects Blender 2.x BF release
Summary Activity Tracker SCM Files

Blender 2.6 Bug Tracker: Browse

[#32581] Mesh properties API does not allow for zeros in byte array

Date:
2012-09-19 06:37
Priority:
3
State:
Closed
Submitted by:
Geoffrey Bantle (briggs)
Assigned to:
Campbell Barton (campbellbarton)
Category:
Python
Status:
Fixed / Closed
Relates to:
Duplicates:
Patches:
 
Summary:
Mesh properties API does not allow for zeros in byte array
Detailed description
easy to reproduce at console with default scene:

layer = bpy.data.meshes["Cube"].polygon_layers_string.new("Data")
layer.data[0].value = bytes([1, 2, 0, 1, 2])
print(layer.data[0].value)

result:

b'\x01\x02'

Followup

Message
  • Date: 2012-09-19 14:33
  • Sender: Campbell Barton
  • Confirmed, to support we need to
    - add a length variable to the MStringProperty struct. so it can have a length besides 256
    - add a callback into rna that can set byte strings - current assignment only takes a 'const char *' which is assumed to be NULL terminated.
    ... a new callback would have to take a length argument too.

    For BMesh support this is simple but for rna a few callbacks would have to support this especially.
  • Date: 2012-09-20 19:42
  • Sender: Geoffrey Bantle
  • Additionally the name of the property layer is misleading, you cannot actually assign strings at all, it must be a bytes object (which makes it especially broken at the moment). I understand this is probably for historical reasons but thought I should mention it anyway.
  • Date: 2013-01-09 14:27
  • Sender: Campbell Barton
  • Committed support for bmesh: r53681.
    # ---
    import bpy
    import bmesh

    me = bpy.context.object.data

    bm = bmesh.new() # create an empty BMesh
    bm.from_mesh(me) # fill it in from a Mesh

    layer = bm.verts.layers.string.new()
    v = bm.verts[0]
    v[layer] = bytes([1, 2, 0, 1, 2])

    print(v[layer])

    bm.to_mesh(me)
    bm.free() # free and prevent further access
 

Attached Files:

No Files Currently Attached

Changes:

Field Old Value Date By
status_idOpen2013-02-19 18:12campbellbarton
close_dateNone2013-02-19 18:12campbellbarton
detailseasy to reproduce at console with default scene: layer = bpy.data.meshes["Cube"].polygon_layers_string.new("Data") layer.data[0].value = bytes([1, 2, 0, 1, 2]) print(layer.data[0].value) result: b\'\\x01\\x02\'2013-02-19 18:12campbellbarton
StatusConfirmed2013-02-19 18:12campbellbarton
detailseasy to reproduce at console with default scene: layer = bpy.data.meshes["Cube"].polygon_layers_string.new("Data") layer.data[0].value = bytes([1, 2, 0, 1, 2]) print(layer.data[0].value) result: b\'\\x01\\x02\'2013-01-09 14:27campbellbarton
detailseasy to reproduce at console with default scene: layer = bpy.data.meshes["Cube"].polygon_layers_string.new("Data") layer.data[0].value = bytes([1, 2, 0, 1, 2]) print(layer.data[0].value) result: b\'\\x01\\x02\'2012-09-20 19:42briggs
detailseasy to reproduce at console with default scene: layer = bpy.data.meshes["Cube"].polygon_layers_string.new("Data") layer.data[0].value = bytes([1, 2, 0, 1, 2]) print(layer.data[0].value) result: b\'\\x01\\x02\'2012-09-19 15:16campbellbarton
StatusNew2012-09-19 15:16campbellbarton
detailseasy to reproduce at console with default scene: layer = bpy.data.meshes["Cube"].polygon_layers_string.new("Data") layer.data[0].value = bytes([1, 2, 0, 1, 2]) print(layer.data[0].value) result: b\'\\x01\\x02\'2012-09-19 14:33campbellbarton