Page MenuHome

New vertex groups cannot be operated upon ... until?
Open, Confirmed, MediumPublic

Description

System Information
Operating system: Windows 10
Graphics card: GTX 970

Blender Version
example: 2.79b release

There is a problem with the way the Blender handles newly created vertex groups that causes numerous problems.

  1. Tools > Weight Tools - These tools do not work on newly created vertex groups.
  2. The Fix Deforms tool immediately crashes blender.
  3. Bmesh cannot access vertex groups layer and returns: AttributeError: BMElem[key]: invalid key, must be a BMLayerItem

To recreate:

  1. Open new Blend
  2. Create Cube
  3. Add Vertex Group
  4. Enter Weight Paint Mode
  5. Press V to enter Vertex Mask mode
  6. If required, press A to select all vertices
  7. Press Tools > Weight Tools > Invert
  8. Nothing happens
  9. Press Fix Deforms
  10. Blender crashes

Using the weight paint brush in an empty space, or manually assigning a vertex to the vertex group in the properties window will allow the weight tools to work as expected. However this is not an acceptable workaround when using Bmesh to manager vertex groups.

Details

Type
Bug

Event Timeline

in the attached file the script fails on the newly created vertex group "Group":

Traceback (most recent call last):

File "C:\Users\Greg\Desktop\untitled2.blend\Text", line 18, in <module>

AttributeError: BMElem[key]: invalid key, must be a BMLayerItem

If the vertex group is initialized such as by assigning vertices to the group manually, prior to running the script, then the script will run without errors.

For a new vertex group:
<Bmesh objects>.verts.layers.deform.items() returns []
<Bmesh object>.verts.layers.deform.active returns None

For a vertex group that has had a manual weight paint brush stroke or vertex assignment in the properties panel, respectively:
[('', <BMLayerItem object at 0x000002D11EB10300>)]
<BMLayerItem object at 0x000002D11EB10300>

Sorry for blowing up the thread, but found a solution: The following script will create the needed BMLayerItem object so that Weight Tools may be used on a newly created Vertex Group

import bpy 
import bmesh

obj = bpy.data.objects['Cube']
group_index = obj.vertex_groups.active_index #Initialize active group

mesh = bpy.data.meshes['Cube']

bm = bmesh.new()
bm.from_mesh(mesh)

bm.verts.layers.deform.verify() #This must be called prior to Weight Tools

bm.to_mesh(mesh)
bm.free()

Jacques Lucke (JacquesLucke) triaged this task as Needs Information from User priority.

Based on your new discoveries, could you please rephrase what the bug is?
Also remember that there should only be one bug per report. If you experience more bugs, create a separate report for each.

The bug is that Weight Tools do not work as expected, possibly because <bmesh>.verts.layers.deform.verify() is needed to fix it

Jacques Lucke (JacquesLucke) raised the priority of this task from Needs Information from User to Needs Triage by Developer.Mar 11 2019, 12:43 PM
Sebastian Parborg (zeddb) triaged this task as Confirmed, Medium priority.

I'm getting this with 2.8 if I follow the instructions in the description:
BLI_assert failed: /home/zed/programmering/blender_master/blender/source/blender/blenkernel/intern/DerivedMesh.c:2294, mesh_get_eval_deform(), at 'ob->id.tag & LIB_TAG_COPIED_ON_WRITE'

And the BT if I disregard the asserts:

Thread 1 "blender" received signal SIGSEGV, Segmentation fault.
0x00005555577614bf in moveCloserToDistanceFromPlane (depsgraph=0x7fffe3351008, scene=0x7fffe4f6a008, ob=0x7fffcf12a808, me=0x7fffcef47908, index=0,
    norm=0x7fffffffd4a4, coord=0x7fffffffd498, d=-0.577350318, distToBe=0, strength=1, cp=1)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/object/object_vgroup.c:1272
1272		int totweight = dvert->totweight;
(gdb) bt
#0  0x00005555577614bf in moveCloserToDistanceFromPlane (depsgraph=0x7fffe3351008, scene=0x7fffe4f6a008, ob=0x7fffcf12a808, me=0x7fffcef47908, index=0,
    norm=0x7fffffffd4a4, coord=0x7fffffffd498, d=-0.577350318, distToBe=0, strength=1, cp=1)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/object/object_vgroup.c:1272
#1  0x000055555776246a in vgroup_fix (C=0x7fffea058188, scene=0x7fffe4f6a008, ob=0x7fffcf12a808, distToBe=0, strength=1, cp=1)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/object/object_vgroup.c:1479
#2  0x000055555776a288 in vertex_group_fix_exec (C=0x7fffea058188, op=0x7fffd8479988)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/object/object_vgroup.c:3017
#3  0x0000555557224fde in wm_operator_invoke (C=0x7fffea058188, ot=0x7fffe4d66e88, event=0x7fffd8476a08, properties=0x7fffffffd6f0, reports=0x0,
    poll_only=false, use_last_properties=true) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:1353
#4  0x000055555722567b in wm_operator_call_internal (C=0x7fffea058188, ot=0x7fffe4d66e88, properties=0x7fffffffd6f0, reports=0x0, context=1, poll_only=false,
    event=0x7fffd8476a08) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:1550
#5  0x000055555722589e in WM_operator_name_call_ptr (C=0x7fffea058188, ot=0x7fffe4d66e88, context=1, properties=0x7fffffffd6f0)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:1598
#6  0x0000555557569006 in ui_apply_but_funcs_after (C=0x7fffea058188)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/interface/interface_handlers.c:770
#7  0x0000555557581e56 in ui_handler_region_menu (C=0x7fffea058188, event=0x7fffcc355b88, UNUSED_userdata=0x7fffd850e308)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/interface/interface_handlers.c:9903
#8  0x0000555557222c66 in wm_handler_ui_call (C=0x7fffea058188, handler=0x7fffcf14c268, event=0x7fffcc355b88, always_pass=0)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:585
#9  0x0000555557227da0 in wm_handlers_do_intern (C=0x7fffea058188, event=0x7fffcc355b88, handlers=0x7fffe4e52198)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:2491
#10 0x0000555557228777 in wm_handlers_do (C=0x7fffea058188, event=0x7fffcc355b88, handlers=0x7fffe4e52198)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:2720
#11 0x00005555572299ab in wm_event_do_handlers (C=0x7fffea058188)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:3071
#12 0x000055555721e1cf in WM_main (C=0x7fffea058188) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm.c:418
#13 0x0000555557218904 in main (argc=1, argv=0x7fffffffdd28) at /home/zed/programmering/blender_master/blender/source/creator/creator.c:505

@Greg (sok0), can you explain me what the "Fix Deforms" operation is supposed to do?
Could not find any useful information. The code for it seems to be bad in many regards.
Also I found this: T32406
Does not look like this has ever been corrected.

@Greg (sok0), can you explain me what the "Fix Deforms" operation is supposed to do?

I've read the documentation and I assumed it was some kind of algorithm that adjusts ratios of bone weights for deforms that cause excessive clipping. In practice i've never seen it do anything.

Sergey Sharybin (sergey) removed Sergey Sharybin (sergey) as the assignee of this task.

@Sebastian Parborg (zeddb), i've made current master (rB9d269a97be5) to work the same as 2.79 with "Fix Deform". There is no much more i can do here.
The original report is about 2.79, and i can only make .280 work same as 2.79 in areas i am absolutely not familiar with.