BMesh.free causes crash under curtain conditions #96791

Open
opened 2022-03-26 09:28:38 +01:00 by Jan Ondrej · 31 comments

System Information
Operating system: Linux-5.16.16-200.fc35.x86_64-x86_64-with-glibc2.34 64 Bits
Graphics card: NVIDIA GeForce GTX 1660 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.47.03

Blender Version
Broken: version: 3.2.0 Alpha, branch: master, commit date: 2022-03-25 21:17, hash: 1909fd2781

all 3.x versions are broken, 3.0.0 sometimes works

Worked: 2.93.8 LTS
On Fedora also some 2.91 versions have been affected, according to rebuild agains newer pythons.
Reported on redhat bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1872980

Short description of error
blender.crash.txt
Using my python addon blender crashes on _PyEval_EvalFrameDefault or _Py_Dealloc.

Exact steps for others to reproduce the error
Unable to describe simple steps to reproduce. This happens using my python addon, but if a bug is in addon, still shouldn't crash blender but throw an python traceback.
When I delete line describen in crash log's backtrace, then another row is marked as a problem, so unable to identify exactly what's happening.
Please, let me know, if you need more information.


Edit, run this script with the following command line arguments: boxmaker_crash_single_script.py
blender -b --factory-startup --python boxmaker_crash_single_script.py

**System Information** Operating system: Linux-5.16.16-200.fc35.x86_64-x86_64-with-glibc2.34 64 Bits Graphics card: NVIDIA GeForce GTX 1660 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.47.03 **Blender Version** Broken: version: 3.2.0 Alpha, branch: master, commit date: 2022-03-25 21:17, hash: `1909fd2781` ``` all 3.x versions are broken, 3.0.0 sometimes works ``` Worked: 2.93.8 LTS On Fedora also some 2.91 versions have been affected, according to rebuild agains newer pythons. Reported on redhat bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1872980 **Short description of error** [blender.crash.txt](https://archive.blender.org/developer/F12947980/blender.crash.txt) Using my python addon blender crashes on _PyEval_EvalFrameDefault or _Py_Dealloc. **Exact steps for others to reproduce the error** Unable to describe simple steps to reproduce. This happens using my python addon, but if a bug is in addon, still shouldn't crash blender but throw an python traceback. When I delete line describen in crash log's backtrace, then another row is marked as a problem, so unable to identify exactly what's happening. Please, let me know, if you need more information. ---- Edit, run this script with the following command line arguments: [boxmaker_crash_single_script.py](https://archive.blender.org/developer/F13052503/boxmaker_crash_single_script.py) `blender -b --factory-startup --python boxmaker_crash_single_script.py`
Author

Added subscriber: @ondrejj

Added subscriber: @ondrejj
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

Hi, thanks for the report.
Not necessary that the crash caused by Python script is a bug in Blender code.
We use this canned response if crash or error is introduced by their own python script.
Crashes or errors involving your own C/C++ code (Python C/API for example) will only be accepted as bugs if you are able to identify the error in Blender's code. Finding that your code isn't working as expected in Blender isn't sufficient to consider it a Blender bug as there may be other reasons that aren't necessarily caused by errors in Blender's code.

Hi, thanks for the report. Not necessary that the crash caused by Python script is a bug in Blender code. We use this canned response if crash or error is introduced by their own python script. ```Crashes or errors involving your own C/C++ code (Python C/API for example) will only be accepted as bugs if you are able to identify the error in Blender's code. Finding that your code isn't working as expected in Blender isn't sufficient to consider it a Blender bug as there may be other reasons that aren't necessarily caused by errors in Blender's code.```

Added subscriber: @StephenSwaney

Added subscriber: @StephenSwaney

/me bets on a reference counting error.

/me bets on a reference counting error.
Author

Hello. Thanks for reply. My script is only plain python, using only bpy, mesh and mathutils (only Vector) modules. No extenal C code. This is the reason why I reported this here.

If you wish, I can share my python script, even if it's not ready for public. My script also needs some interaction, which I can't fully describe, so I don't know if it helps.

Hello. Thanks for reply. My script is only plain python, using only bpy, mesh and mathutils (only Vector) modules. No extenal C code. This is the reason why I reported this here. If you wish, I can share my python script, even if it's not ready for public. My script also needs some interaction, which I can't fully describe, so I don't know if it helps.

Added subscriber: @deadpin

Added subscriber: @deadpin

Either way, we need a way to reproduce the crash. We can't, and won't, debug through an entire addon to do so. A simplified repro is necessary. Strip out as much as possible until you arrive at only the pieces that are necessary.

Either way, we need a way to reproduce the crash. We can't, and won't, debug through an entire addon to do so. A simplified repro is necessary. Strip out as much as possible until you arrive at only the pieces that are necessary.
Author

Sorry, I can't reproduce this in a small script, however I found a problem. Using this function fails:

def bevel(cover, offset, segments=10):
    bm = bmesh.from_edit_mesh(cover.data)
    bmesh.ops.bevel(bm,
      geom=[x for x in bm.verts[:]+bm.edges[:] if x.select],
      offset=offset,
      offset_type='OFFSET',
      segments=segments,
      profile=0.5,
      affect="EDGES", #vertex_only=False,
      loop_slide=True,
      clamp_overlap=True
    )
    bmesh.update_edit_mesh(cover.data)
    bm.free()

After removal of bm.free(), script works again.
@StephenSwaney, thank you for pointing me to an referencing error.

Why this bm.free() exists and should or shouldn't be called? In blender's documentation I found, that I should call it.

Sorry, I can't reproduce this in a small script, however I found a problem. Using this function fails: ``` def bevel(cover, offset, segments=10): bm = bmesh.from_edit_mesh(cover.data) bmesh.ops.bevel(bm, geom=[x for x in bm.verts[:]+bm.edges[:] if x.select], offset=offset, offset_type='OFFSET', segments=segments, profile=0.5, affect="EDGES", #vertex_only=False, loop_slide=True, clamp_overlap=True ) bmesh.update_edit_mesh(cover.data) bm.free() ``` After removal of bm.free(), script works again. @StephenSwaney, thank you for pointing me to an referencing error. Why this bm.free() exists and should or shouldn't be called? In blender's documentation I found, that I should call it.
Member

I think it's not necessary to call bm.free()
Data is expected to get freed at the end of function execution.

We may handle this as a valid report if that call is responsible for the crash.

I think it's not necessary to call bm.free() Data is expected to get freed at the end of function execution. We may handle this as a valid report if that call is responsible for the crash.
Author

I can confirm, that reenable of bm.free() will crash again and after removal it's back.

This script doesn't crash on bm.free() or at end of function, but crashes aprox. 10 rows after return from this function. May be crash log from this report can help to identify, what's happening.

My initial problem has been solved by removing of bm.free(), but I am ready to do more tests if needed. Just let me know, how I can help.

I can confirm, that reenable of bm.free() will crash again and after removal it's back. This script doesn't crash on bm.free() or at end of function, but crashes aprox. 10 rows after return from this function. May be crash log from this report can help to identify, what's happening. My initial problem has been solved by removing of bm.free(), but I am ready to do more tests if needed. Just let me know, how I can help.
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

This script doesn't crash on bm.free() or at end of function, but crashes aprox. 10 rows after return from this function. May be crash log from this report can help to identify, > what's happening.

There might be an issue in your script itself (Still I'm not sure unless we have steps to reproduce it).
Please try one of the community websites: https://www.blender.org/community/
If you think you found a bug, please submit a new report and carefully follow the instructions. Be sure to provide system information, Blender version, and a .blend file with exact steps to reproduce the problem.


Just in case I'm missing something, @lichtwerk, can you check?

> This script doesn't crash on bm.free() or at end of function, but crashes aprox. 10 rows after return from this function. May be crash log from this report can help to identify, > what's happening. There might be an issue in your script itself (Still I'm not sure unless we have steps to reproduce it). Please try one of the community websites: https://www.blender.org/community/ If you think you found a bug, please submit a new report and carefully follow the instructions. Be sure to provide system information, Blender version, and a .blend file with exact steps to reproduce the problem. --- Just in case I'm missing something, @lichtwerk, can you check?
Member

To speed the process up (there are multiple people looking at this already), please always attach a .blend file where this script is already set up to just be executed from the Text Editor.
(This also ensures we are all on the same page)

To speed the process up (there are multiple people looking at this already), please always attach a .blend file where this script is already set up to just be executed from the Text Editor. (This also ensures we are all on the same page)
Author

There is no .blend file. My script is running from blender addons and is using multiple scripts.

There is no .blend file. My script is running from blender addons and is using multiple scripts.
Member

Added subscriber: @ondrew

Added subscriber: @ondrew
Member

@ondrew : than please share that here or try to isolate relevant parts into a script (embedded in a .blend file) with clear steps to reproduce

@ondrew : than please share that here or try to isolate relevant parts into a script (embedded in a .blend file) with clear steps to reproduce
Author

@lichtwerk, you mentioned wrong people. :-)

So ok, I am adding my script. First is: boxmaker.py:
boxmaker.py

Copy this to addons and enable it.

Download pir.py:
pir.py

and run:

blender -P pir.py

This crashes my blender. Not tested today.
Removing of "bm.free()" can fix this script.

Please, do not ask me to make this script simpler. I can't figure, where is the exact problem.

@lichtwerk, you mentioned wrong people. :-) So ok, I am adding my script. First is: boxmaker.py: [boxmaker.py](https://archive.blender.org/developer/F12974711/boxmaker.py) Copy this to addons and enable it. Download pir.py: [pir.py](https://archive.blender.org/developer/F12974677/pir.py) and run: blender -P pir.py This crashes my blender. Not tested today. Removing of "bm.free()" can fix this script. Please, do not ask me to make this script simpler. I can't figure, where is the exact problem.
Member

Removed subscriber: @ondrew

Removed subscriber: @ondrew
Member

Changed status from 'Needs User Info' to: 'Needs Triage'

Changed status from 'Needs User Info' to: 'Needs Triage'
Member

In #96791#1335640, @ondrejj wrote:
@lichtwerk, you mentioned wrong people. :-)

Oops, thx noting

> In #96791#1335640, @ondrejj wrote: > @lichtwerk, you mentioned wrong people. :-) Oops, thx noting

Added subscriber: @ideasman42

Added subscriber: @ideasman42

@ondrejj please make a simple test script that causes the error without relying on a separate add-on.

Any logic that isn't related to reproducing the crash should be removed.

@ondrejj please make a simple test script that causes the error without relying on a separate add-on. Any logic that isn't related to reproducing the crash should be removed.
Author

Sorry, but I can't. My blender script programming is not good enough to do this. I did some experiment but without any success.

Sorry, but I can't. My blender script programming is not good enough to do this. I did some experiment but without any success.

@ondrejj it should not be so difficult to merge the add-on into a script, then remove function calls - checking the crash still occurs.

@ondrejj it should not be so difficult to merge the add-on into a script, then remove function calls - checking the crash still occurs.
Author

But don't know which calls to remove. After removal of one line which makes a problem this problem moves to another line. Sorry, but as I said, I did some experiments, but without success.

But don't know which calls to remove. After removal of one line which makes a problem this problem moves to another line. Sorry, but as I said, I did some experiments, but without success.

@ondrejj uploaded a slightly simplified script with tracing enabled that runs in background mode and crashes reliably, this needs some more investigation though.

Edit: this seems to be memory corruption however it's not clear where exactly this occurs, tested with ASAN and Valgrind don't point to anything obvious.
It looks like the Python state is corrupted some time before the crash occurs.

@ondrejj uploaded a slightly simplified script with tracing enabled that runs in background mode and crashes reliably, this needs some more investigation though. Edit: this seems to be memory corruption however it's not clear where exactly this occurs, tested with ASAN and Valgrind don't point to anything obvious. It looks like the Python state is corrupted some time before the crash occurs.

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Confirmed' to: 'Needs Developer To Reproduce'

Changed status from 'Confirmed' to: 'Needs Developer To Reproduce'
Campbell Barton changed title from Crash using python addon on _PyEval_EvalFrameDefault to BMesh.free causes crash under curtain conditions 2022-05-05 07:28:32 +02:00
Member

Report is already classified as a Bug so can we also mark it as "Confirmed"?

Report is already classified as a `Bug` so can we also mark it as "Confirmed"?
Philipp Oeser removed the
Interest
Modeling
label 2023-02-09 15:27:56 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 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#96791
No description provided.