2
$\begingroup$

Hey I'm running blender 3.3.1 and I am having an issue in my script where I am getting the error EXCEPTION_ACCESS_VIOLATION, the second time that I select a group of polygons. I believe it may be causes by me not selecting or deselecting my polygons correctly from bmesh to bpy, but I am not entirely sure. I have tried stopping my script and looking at where my selection occurs, but it all looks correct from what I can see.

Here is some of the associated code selecting the area to decimate, 'bush.polygons' is a list holding the bmesh faces that I select.

selected_polys = []
invalid_polys = []

self.bm.faces.ensure_lookup_table()

for p in bush.polygons:
    if p.is_valid:
        p.select = True
        for loop in p.loops:
            loop.edge.select = True
            loop.vert.select = True
        selected_polys.append(p)
    else:
        invalid_polys.append(p)

if len(invalid_polys) > 0:
    for p in invalid_polys:
        bush.removePoly(p)

print("Bush %s, Length: %s, Invalid Polys: %s" % (bush_count, len(bush.polygons), len(invalid_polys)))

self.bm.select_flush_mode()
bmesh.update_edit_mesh(self.mesh)

Here is also the code I use to deselect the area. The "selected_polys" is passed in from my selection.

for poly in selected_polys:
    if poly.is_valid:
        poly.select = False

        for loop in poly.loops:
            loop.edge.select = False
            loop.vert.select = False
bmesh.update_edit_mesh(self.mesh)
self.bm.faces.ensure_lookup_table()

Let me know if you need any more information/code posted.

$\endgroup$
1
  • $\begingroup$ Update, I found if i add bpy.ops.mesh.select_more() right before bpy.ops.mesh.decimate() it works correctly $\endgroup$ Commented Jan 2, 2023 at 20:11

1 Answer 1

3
$\begingroup$

I found the solution I needed to use object.update_from_editmode() for the bmesh to update and see the changes. It was crashing because I was selecting bmesh polygons that didn't exist on the bpy mesh.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .