FreeCAD / FreeCAD-macros

A repository for FreeCAD macros
https://freecad.org/wiki/Macros_recipes
163 stars 140 forks source link

CenterOfMass: Use of already-deleted C++ object #178

Open jes opened 1 month ago

jes commented 1 month ago

I originally reported this on https://github.com/FreeCAD/FreeCAD/issues/17447

Traceback (most recent call last):
  File "/home/jes/snap/freecad/common/CenterOfMass.FCMacro", line 551, in on_focusChanged
    if w is not None and w.parent() == self.solidLayout.parentWidget():
RuntimeError: Internal C++ object (PySide2.QtWidgets.QWidget) already deleted.

I'm running FreeCAD 0.21.2 on Ubuntu 24.04 from the Snap store. In that version this bug causes a segfault, but in the "latest/edge" version the segfault is fixed and the above error message appears.


I found that with a particular file (in the attached zip file sovereign-scales4.zip ), I can reliably trigger a segfault as follows:

And then FreeCAD instantly segfaults. I did try to simplify this by skipping all of the steps to do with the CenterOfMass macro but could not reproduce the problem without using CenterOfMass. I haven't exhaustively searched to find out whether every single click is necessary, but hopefully this is useful enough as a bug report.

I have a screen recording demonstrating the problem here: https://www.youtube.com/watch?v=VMFdUpOoCko

Full version info

[code]
OS: Ubuntu Core 20 (ubuntu:GNOME/ubuntu)
Word size of FreeCAD: 64-bit
Version: 0.21.2.33771 (Git) Snap 908
Build type: Release
Branch: tag: 0.21.2
Hash: b9bfa5c5507506e4515816414cd27f4851d00489
Python 3.8.10, Qt 5.15.7, Coin 4.0.0, Vtk 7.1.1, OCC 7.6.3
Locale: English/United Kingdom (en_GB)
[/code]

Anything else?

This is the log from the terminal, including a backtrace: 100135.txt

Apart from the segfault there appears to be a use of deprecated implicit type conversion in CenterOfMass:

/home/jes/snap/freecad/common/CenterOfMass.FCMacro:307: DeprecationWarning: an integer is required (got type PySide2.QtCore.Qt.AlignmentFlag).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
  label_comboUnit.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
galou commented 4 days ago

@s-quirin