Maniphest T96791

BMesh.free causes crash under curtain conditions
Needs Information from Developers, NormalBUG

Assigned To
None
Authored By
Jan Ondrej (ondrejj)
Mar 26 2022, 9:28 AM
Tags
  • BF Blender
  • Python API
  • Modeling
Subscribers
Campbell Barton (campbellbarton)
Jan Ondrej (ondrejj)
Jesse Yurkovich (deadpin)
Philipp Oeser (lichtwerk)
Pratik Borhade (PratikPB2123)
Stephen Swaney (stiv)

Description

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: rB1909fd2781c4

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


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:


blender -b --factory-startup --python boxmaker_crash_single_script.py

Event Timeline

Jan Ondrej (ondrejj) created this task.Mar 26 2022, 9:28 AM
Pratik Borhade (PratikPB2123) changed the task status from Needs Triage to Needs Information from User.Mar 26 2022, 10:15 AM
Pratik Borhade (PratikPB2123) added a subscriber: Pratik Borhade (PratikPB2123).

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.
Stephen Swaney (stiv) added a subscriber: Stephen Swaney (stiv).Mar 26 2022, 4:30 PM

/me bets on a reference counting error.

Jan Ondrej (ondrejj) added a comment.Mar 26 2022, 6:23 PM

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.

Jesse Yurkovich (deadpin) added a subscriber: Jesse Yurkovich (deadpin).Mar 26 2022, 9:29 PM

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.

Jan Ondrej (ondrejj) added a comment.Mar 27 2022, 11:10 AM

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.
@Stephen Swaney (stiv), 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.

Pratik Borhade (PratikPB2123) added a comment.Mar 28 2022, 5:20 AM

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.

Jan Ondrej (ondrejj) added a comment.Mar 28 2022, 7:52 AM

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.

Pratik Borhade (PratikPB2123) added a subscriber: Philipp Oeser (lichtwerk).Apr 5 2022, 9:27 AM

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, @Philipp Oeser (lichtwerk), can you check?

Philipp Oeser (lichtwerk) added a comment.Apr 5 2022, 10:12 AM

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)

Jan Ondrej (ondrejj) added a comment.Apr 5 2022, 10:25 AM

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

Philipp Oeser (lichtwerk) added a subscriber: Ondrej Novak (ondrew).Apr 5 2022, 10:37 AM

@Ondrej Novak (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

Jan Ondrej (ondrejj) added a comment.Apr 5 2022, 10:46 AM

@Philipp Oeser (lichtwerk), you mentioned wrong people. :-)

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

Copy this to addons and enable it.

Download 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.

Philipp Oeser (lichtwerk) changed the task status from Needs Information from User to Needs Triage.Apr 5 2022, 11:11 AM
Philipp Oeser (lichtwerk) removed a subscriber: Ondrej Novak (ondrew).
In T96791#1335640, @Jan Ondrej (ondrejj) wrote:

@Philipp Oeser (lichtwerk), you mentioned wrong people. :-)

Oops, thx noting

Campbell Barton (campbellbarton) added a subscriber: Campbell Barton (campbellbarton).EditedMay 4 2022, 7:43 AM

@Jan Ondrej (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.

Jan Ondrej (ondrejj) added a comment.May 4 2022, 7:46 AM

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

Campbell Barton (campbellbarton) added a comment.May 4 2022, 7:52 AM

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

Jan Ondrej (ondrejj) added a comment.May 4 2022, 7:54 AM

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.

Campbell Barton (campbellbarton) updated the task description.May 5 2022, 7:13 AM
Campbell Barton (campbellbarton) added a comment.EditedMay 5 2022, 7:26 AM

@Jan Ondrej (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.

Campbell Barton (campbellbarton) changed the task status from Needs Triage to Confirmed.May 5 2022, 7:26 AM
Campbell Barton (campbellbarton) changed the task status from Confirmed to Needs Information from Developers.
Campbell Barton (campbellbarton) changed the subtype of this task from "Report" to "Bug".
Campbell Barton (campbellbarton) renamed this task from Crash using python addon on _PyEval_EvalFrameDefault to BMesh.free causes crash under curtain conditions.May 5 2022, 7:28 AM
Pratik Borhade (PratikPB2123) added projects: Python API, Modeling.Aug 17 2022, 2:04 AM

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