Page MenuHome

bm.*.sort() leads to strange bytes object and crashes occasionally
Closed, ResolvedPublic

Description

System Information
Windows 8.1, 64bit

Blender Version
Broken: 2.75a official

Short description of error

Exact steps for others to reproduce the error
Add a Plane, go to edit mode and run below script several times. It should eventually produce an error that bytes object does not have property "index" or "co". Subsequent runs of the script or clicks in viewport may crash Blender.

import bpy
import bmesh
import random

ob = bpy.context.object
assert ob.type == "MESH"
me = ob.data

bm = bmesh.from_edit_mesh(me)
new_order = list(range(len(bm.verts)))
random.shuffle(new_order)

for i, v in zip(new_order, bm.verts):
    v.index = i

print("shuffled indices:")
for v in bm.verts:
    print(v.index)

print("update index()")    
bm.verts.index_update()

print("indices returned to original order:")
for v in bm.verts:
    print(v.index, v.co.xy)

print("shuffling again, followed by a sort:")
for i, v in zip(new_order, bm.verts):
    v.index = i
bm.verts.sort()

for v in bm.verts:
    print(v.index, v.co.xy)
    
bmesh.update_edit_mesh(me)

Revisions and Commits

Event Timeline

codemanx raised the priority of this task from to 90.
codemanx updated the task description. (Show Details)
codemanx edited a custom field.
codemanx added a subscriber: codemanx.

Can confirm the crash, it actually happens first time you run the script with asan enabled.

I'm not sure if there's some obvious mistake in the py code, will let @Campbell Barton (campbellbarton) to decide :)

Sergey Sharybin (sergey) lowered the priority of this task from 90 to 50.Aug 29 2015, 11:26 AM

I can't get this to crash.
Even playing back animation (in edit-mode), while holding Enter, over the run script button - is working fine.

Tested with valgrind and asan, - no errors in either.

@Sergey Sharybin (sergey), whats the report you get?

All it prints to console is "Error: EXCEPTION_ACCESS_VIOLATION".

@Sergey Sharybin (sergey) / @Campbell Barton (campbellbarton): What OS did you try this on? And what exact Blender version?

Error occurs at least on Windows 8, 64bit in every version since the introduction of sort(), which was 2.64 (had to adapt the test script, because update_edit_mesh() didn't exist back then). I tried 32 and 64 bit releases.

In 2.64, the error is slightly different: 'PyCapsule' object has no attribute 'index' .

It's definitely the sort() call, if I comment it out, everything is fine.