Remove doubles Operator crash called from a script in a specific case #51483

Closed
opened 2017-05-13 03:17:40 +02:00 by Vuk Gardašević · 11 comments

System Information
Win 7 64 bit, Amd X3 455, R7 360

Blender Version
Broken: 717d85f, ac880b6

Short description of error
Using both the operator and Bmesh Remove doubles variants in a script on a specific mesh in a specific location, can cause Blender to crash
edges_to_wall_crash.jpg

Exact steps for others to reproduce the error
Enable Edit Tools 2 add-on > Default cube > Edit mode > Mesh Edit Tools in the Tools Region (T panel known among the people) > Edge Tools > Roundify ( default settings) > Edges(s) to Wall.

The error:

Traceback (most recent call last):
  File "2.78\scripts\addons\mesh_extra_tools\mesh_to_wall.py", line 218, in execute
    lp = turn_left(bm, j, i, vm, wm)
  File "2.78\scripts\addons\mesh_extra_tools\mesh_to_wall.py", line 74, in turn_left
    v = verts.index(links[-2])
ValueError: 0 is not in list

location: <unknown location>:-1

Error: EXCEPTION_ACCESS_VIOLATION

After some investigation the culprit is in the mesh_to_wall script.
Changing the code in the MeshtoWall operator - moving the remove doubles code to be called first in the execute would prevent crashing.
It didn' matter if the bmesh.ops was replaced with the bpy.ops. However, just commenting out the bmesh.ops.remove_doubles line is enough to make the operator run properly.

Original code around line 190 (crashes) :

    def execute(self, context):
        bpy.ops.object.mode_set(mode='OBJECT')
        if self.check_vert(context):
            bpy.ops.object.mode_set(mode='EDIT')
            ob = bpy.context.object
            bm = bmesh.from_edit_mesh(ob.data)
            bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.003)   # <<< This line here
            bmesh.ops.delete(bm, geom=bm.faces, context=3)
            context.tool_settings.mesh_select_mode = (True, True, False)

Modified code (doesn't crash)

    def execute(self, context):
        - Note: the remove_doubles called after bmesh creation would make
        - blender crash with certain meshes - keep it in mind for the future
        bpy.ops.mesh.remove_doubles(threshold=0.003)  # <<< Remove doubles is called from here
        bpy.ops.object.mode_set(mode='OBJECT')
        if self.check_vert(context):
            bpy.ops.object.mode_set(mode='EDIT')
            ob = bpy.context.object

            me = ob.data
            bm = bmesh.from_edit_mesh(me)
            bmesh.ops.delete(bm, geom=bm.faces, context=3)
            context.tool_settings.mesh_select_mode = (True, True, False)

Concerning the output from the Roundify operator (class EdgeRoundifierin the script mesh_edge_roundifier ) the produced mesh is valid as other tools are capable of further edits.
Commenting out the bm.free() line at the end of the operator doesn't have any impact on preventing the crash.

**System Information** Win 7 64 bit, Amd X3 455, R7 360 **Blender Version** Broken: `717d85f`, ` ac880b6` **Short description of error** Using both the operator and Bmesh Remove doubles variants in a script on a specific mesh in a specific location, can cause Blender to crash ![edges_to_wall_crash.jpg](https://archive.blender.org/developer/F596959/edges_to_wall_crash.jpg) **Exact steps for others to reproduce the error** Enable Edit Tools 2 add-on > Default cube > Edit mode > Mesh Edit Tools in the Tools Region (T panel known among the people) > Edge Tools > Roundify ( default settings) > Edges(s) to Wall. The error: ``` Traceback (most recent call last): File "2.78\scripts\addons\mesh_extra_tools\mesh_to_wall.py", line 218, in execute lp = turn_left(bm, j, i, vm, wm) File "2.78\scripts\addons\mesh_extra_tools\mesh_to_wall.py", line 74, in turn_left v = verts.index(links[-2]) ValueError: 0 is not in list location: <unknown location>:-1 Error: EXCEPTION_ACCESS_VIOLATION ``` After some investigation the culprit is in the mesh_to_wall script. Changing the code in the MeshtoWall operator - moving the remove doubles code to be called first in the execute would prevent crashing. It didn' matter if the bmesh.ops was replaced with the bpy.ops. However, just commenting out the `bmesh.ops.remove_doubles` line is enough to make the operator run properly. Original code around line 190 (crashes) : ``` def execute(self, context): bpy.ops.object.mode_set(mode='OBJECT') if self.check_vert(context): bpy.ops.object.mode_set(mode='EDIT') ob = bpy.context.object bm = bmesh.from_edit_mesh(ob.data) bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.003) # <<< This line here bmesh.ops.delete(bm, geom=bm.faces, context=3) context.tool_settings.mesh_select_mode = (True, True, False) ``` Modified code (doesn't crash) ``` def execute(self, context): - Note: the remove_doubles called after bmesh creation would make - blender crash with certain meshes - keep it in mind for the future bpy.ops.mesh.remove_doubles(threshold=0.003) # <<< Remove doubles is called from here bpy.ops.object.mode_set(mode='OBJECT') if self.check_vert(context): bpy.ops.object.mode_set(mode='EDIT') ob = bpy.context.object me = ob.data bm = bmesh.from_edit_mesh(me) bmesh.ops.delete(bm, geom=bm.faces, context=3) context.tool_settings.mesh_select_mode = (True, True, False) ``` Concerning the output from the Roundify operator (*class EdgeRoundifier*in the script `mesh_edge_roundifier` ) the produced mesh is valid as other tools are capable of further edits. Commenting out the `bm.free() ` line at the end of the operator doesn't have any impact on preventing the crash.
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @VukGardasevic

Added subscriber: @VukGardasevic
Member

Added subscriber: @BrendonMurphy

Added subscriber: @BrendonMurphy
Member

confirmed.
Will also note that neither addon is designed to work on solid mesh.
I think we need to fix this asap.

confirmed. Will also note that neither addon is designed to work on solid mesh. I think we need to fix this asap.

Added subscriber: @Sergey

Added subscriber: @Sergey
Brendon Murphy was assigned by Sergey Sharybin 2017-05-15 12:00:18 +02:00

@BrendonMurphy, you are listed as an author. So assigning to you.

@BrendonMurphy, you are listed as an author. So assigning to you.
Member

hi, @Sergey, I have discussed this with @VukGardasevic we will have ready.
I've found the actual offending line is line 200 in mesh to wall.
changing this line to:

 bpy.ops.mesh.delete(type='FACE')

is a hacky way to prevent the crash, but works & exposes the value error 0 addon fail.
this should be handled by an exception & the user warned "Zero Area faces, please use on single axis" or other pop up warning & the addon pass/prevent execute.

thanks, looking into it more before committing.

hi, @Sergey, I have discussed this with @VukGardasevic we will have ready. I've found the actual offending line is line 200 in mesh to wall. changing this line to: ``` bpy.ops.mesh.delete(type='FACE') ``` is a hacky way to prevent the crash, but works & exposes the value error 0 addon fail. this should be handled by an exception & the user warned "Zero Area faces, please use on single axis" or other pop up warning & the addon pass/prevent execute. thanks, looking into it more before committing.
Author
Member

Replaced the original script with the a new bmesh operator variant. See in the previous commit.
Since the script suffered from performance issues too. Now, Mesh to wall can be added to contrib as the replacement module is not a 1 to 1 replacement as it does things differently.
@BrendonMurphy
if it is okay we could add it back to the contrib if someone is interested in maintaining/fixing it - fix the bad memory access of the mesh elements and improve performance.

I'll leave this task open until a solution to the script in question is found.

Replaced the original script with the a new bmesh operator variant. See in the previous commit. Since the script suffered from performance issues too. Now, Mesh to wall can be added to contrib as the replacement module is not a 1 to 1 replacement as it does things differently. @BrendonMurphy if it is okay we could add it back to the contrib if someone is interested in maintaining/fixing it - fix the bad memory access of the mesh elements and improve performance. I'll leave this task open until a solution to the script in question is found.
Member

go ahead & close
your rewrite is very good, mesh to wall does do things slightly different, but it's not developed outside mesh edit tools, so, no need to move to contrib.
Thanks. great Job :)

go ahead & close your rewrite is very good, mesh to wall does do things slightly different, but it's not developed outside mesh edit tools, so, no need to move to contrib. Thanks. great Job :)
Author
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Author
Member

If someone wants to pickup the Mesh to Wall add-on feel free to do so and it will be included back in contrib.
All right i'll archive the task then :)

If someone wants to pickup the Mesh to Wall add-on feel free to do so and it will be included back in contrib. All right i'll archive the task then :)
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#51483
No description provided.