FreeCAD crashes when clearing an expression in an onChanged handler.

Need help, or want to share a macro? Post here!
Post Reply
suzanne.soy
Posts: 54
Joined: Sat Dec 19, 2020 11:55 pm

FreeCAD crashes when clearing an expression in an onChanged handler.

Post by suzanne.soy »

Can someone confirm this so that I may open a bug report? Thanks :)

Steps to reproduce:
  • Open FreeCAD
  • Paste the following in the Python console and press Return (twice if needed)

    Code: Select all

    if True:
        App.newDocument("Document")
        obj = App.ActiveDocument.addObject("App::DocumentObjectGroupPython", "Obj")
        class Cls():
            def __init__(self, obj):
                self.MonitorChanges = False
                obj.Proxy = self
                obj.addProperty('App::PropertyFloat', "propA", "group")
                obj.addProperty('App::PropertyFloat', "propB", "group")
                self.MonitorChanges = True
                obj.setExpression("propB", '6*9')
            def onChanged(self, obj, prop):
                print("onChanged",self, obj, prop)
                if (self.MonitorChanges and prop == "propA"):
                    print('Removing expression...')
                    obj.setExpression("propB", None)
        Cls(obj)
    
    
    
  • Click on the "Obj" object that was created
  • Click on the "prop A" property
  • type "=42" (which opens the formula editor)
  • press Return twice
  • FreeCAD crashes (backtrace at the end of this post)
I have tested this on the latest version:

Code: Select all

OS: Ubuntu 20.04.2 LTS (wayfire)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24291 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.19.2)
Hash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.8
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United Kingdom (en_GB)
Backtrace:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
#0  /lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7f1dbb0e6210]
#1  0x7f1dbcf53cd4 in App::Expression::getPyValue() const from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADApp.so+0x34
#2  0x7f1dbcf54448 in App::Expression::getValueAsAny() const from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADApp.so+0x38
#3  0x7f1dbd0598d3 in App::PropertyExpressionEngine::execute(App::PropertyExpressionEngine::ExecuteOption, bool*) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADApp.so+0x233
#4  0x7f1dbce76667 in App::Document::_recomputeFeature(App::DocumentObject*) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADApp.so+0x147
#5  0x7f1dbced1dd6 in App::Document::recompute(std::vector<App::DocumentObject*, std::allocator<App::DocumentObject*> > const&, bool, bool*, int) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADApp.so+0x5c6
#6  0x7f1dbdc47b61 in Gui::PropertyEditor::PropertyEditor::recomputeDocument(App::Document*) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADGui.so+0x81
#7  0x7f1dbdc47c22 in Gui::PropertyEditor::PropertyEditor::closeTransaction() from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADGui.so+0x92
#8  0x7f1dbdc4c24e in Gui::PropertyEditor::PropertyEditor::closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADGui.so+0x3e
#9  /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Widgets.so.5(+0x2f84ff) [0x7f1dbbf8c4ff]
#10  0x7f1dbb5f8a18 in QMetaObject::activate(QObject*, int, int, void**) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Core.so.5+0x6c0
#11  0x7f1dbbf997f4 in QAbstractItemDelegate::closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Widgets.so.5+0x40
#12  0x7f1dbb5f7594 in QObject::event(QEvent*) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Core.so.5+0xbc
#13  0x7f1dbbe087f2 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Widgets.so.5+0xdc
#14  0x7f1dbbe0e31d in QApplication::notify(QObject*, QEvent*) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Widgets.so.5+0x1ac9
#15  0x7f1dbd9b8df9 in Gui::GUIApplication::notify(QObject*, QEvent*) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADGui.so+0x89
#16  0x7f1dbb5e2606 in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Core.so.5+0x86
#17  0x7f1dbb5e283e in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Core.so.5+0x1da
#18  /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Core.so.5(+0x1dc54c) [0x7f1dbb61154c]
#19  /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/./libglib-2.0.so.0(g_main_context_dispatch+0x27d) [0x7f1db852b23d]
#20  /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/./libglib-2.0.so.0(+0x554d1) [0x7f1db852b4d1]
#21  /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/./libglib-2.0.so.0(g_main_context_iteration+0x31) [0x7f1db852b571]
#22  0x7f1dbb6110e8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Core.so.5+0x5e
#23  0x7f1dbb5df019 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Core.so.5+0x187
#24  0x7f1dbb5e2e8f in QCoreApplication::exec() from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libQt5Core.so.5+0xfd
#25  0x7f1dbd942926 in Gui::Application::runApplication() from /tmp/.mount_FreeCAm4IC5c/usr/bin/../lib/libFreeCADGui.so+0x15f6
#26  /tmp/.mount_FreeCAm4IC5c/usr/bin/freecad(+0x44bf) [0x564432e404bf]
#27  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f1dbb0c70b3]
#28  /tmp/.mount_FreeCAm4IC5c/usr/bin/freecad(+0x47d9) [0x564432e407d9]
:?: Please mark your posts as [solved] :!:
:idea: If the answer you got is a good fit for the wiki, you can edit it!
FreeCAD modelling & coding workbenches+macros: twitch GitHub
edi
Posts: 449
Joined: Fri Jan 17, 2020 1:32 pm

Re: FreeCAD crashes when clearing an expression in an onChanged handler.

Post by edi »

I can confirm the issue. It occures only when entering an expression a the first change.

If you input a simple value at the first change, then enter an expression at the second change, no crash occures.

OS: Ubuntu 20.04.2 LTS (Unity:Unity7:ubuntu/unity)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24267 (Git) AppImage
Build type: Release
Branch: master
Hash: b2ca86d8d72b636011a73394bf9bcdedb3b109b7
Python version: 3.8.6
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: German/Austria (de_AT)
suzanne.soy
Posts: 54
Joined: Sat Dec 19, 2020 11:55 pm

Re: FreeCAD crashes when clearing an expression in an onChanged handler.

Post by suzanne.soy »

:?: Please mark your posts as [solved] :!:
:idea: If the answer you got is a good fit for the wiki, you can edit it!
FreeCAD modelling & coding workbenches+macros: twitch GitHub
User avatar
onekk
Veteran
Posts: 5623
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: FreeCAD crashes when clearing an expression in an onChanged handler.

Post by onekk »

Code: Select all

FreeCAD 0.19, Libs: 0.19R24291 (Git)
© Juergen Riegel, Werner Mayer, Yorik van Havre and others 2001-2021
FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.
FreeCAD wouldn't be possible without FreeCAD community.
  #####                 ####  ###   ####  
  #                    #      # #   #   # 
  #     ##  #### ####  #     #   #  #   # 
  ####  # # #  # #  #  #     #####  #   # 
  #     #   #### ####  #    #     # #   # 
  #     #   #    #     #    #     # #   #  ##  ##  ##
  #     #   #### ####   ### #     # ####   ##  ##  ##

onChanged <__main__.Cls object at 0x7f1331326dc0> <group object> Proxy
onChanged <__main__.Cls object at 0x7f1331326dc0> <group object> ExpressionEngine
onChanged <__main__.Cls object at 0x7f1331326dc0> <group object> propB
onChanged <__main__.Cls object at 0x7f1331326dc0> <group object> _GroupTouched
onChanged <__main__.Cls object at 0x7f1331326dc0> <group object> ExpressionEngine
onChanged <__main__.Cls object at 0x7f1331326dc0> <group object> ExpressionEngine
onChanged <__main__.Cls object at 0x7f1331326dc0> <group object> propA
Removing expression...
onChanged <__main__.Cls object at 0x7f1331326dc0> <group object> ExpressionEngine
Program received signal SIGSEGV, Segmentation fault.
#0  /usr/lib/libc.so.6(+0x3cf80) [0x7f1355d11f80]
#1  0x7f1357b6fcd4 in App::Expression::getPyValue() const from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADApp.so+0x34
#2  0x7f1357b70448 in App::Expression::getValueAsAny() const from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADApp.so+0x38
#3  0x7f1357c758d3 in App::PropertyExpressionEngine::execute(App::PropertyExpressionEngine::ExecuteOption, bool*) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADApp.so+0x233
#4  0x7f1357a92667 in App::Document::_recomputeFeature(App::DocumentObject*) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADApp.so+0x147
#5  0x7f1357aeddd6 in App::Document::recompute(std::vector<App::DocumentObject*, std::allocator<App::DocumentObject*> > const&, bool, bool*, int) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADApp.so+0x5c6
#6  0x7f1358863b61 in Gui::PropertyEditor::PropertyEditor::recomputeDocument(App::Document*) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADGui.so+0x81
#7  0x7f1358863c22 in Gui::PropertyEditor::PropertyEditor::closeTransaction() from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADGui.so+0x92
#8  0x7f135886824e in Gui::PropertyEditor::PropertyEditor::closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADGui.so+0x3e
#9  /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Widgets.so.5(+0x2f84ff) [0x7f1356ba84ff]
#10  0x7f1356214a18 in QMetaObject::activate(QObject*, int, int, void**) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Core.so.5+0x6c0
#11  0x7f1356bb57f4 in QAbstractItemDelegate::closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Widgets.so.5+0x40
#12  0x7f1356213594 in QObject::event(QEvent*) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Core.so.5+0xbc
#13  0x7f1356a247f2 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Widgets.so.5+0xdc
#14  0x7f1356a2a31d in QApplication::notify(QObject*, QEvent*) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Widgets.so.5+0x1ac9
#15  0x7f13585d4df9 in Gui::GUIApplication::notify(QObject*, QEvent*) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADGui.so+0x89
#16  0x7f13561fe606 in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Core.so.5+0x86
#17  0x7f13561fe83e in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Core.so.5+0x1da
#18  /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Core.so.5(+0x1dc54c) [0x7f135622d54c]
#19  /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/./libglib-2.0.so.0(g_main_context_dispatch+0x27d) [0x7f135316d23d]
#20  /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/./libglib-2.0.so.0(+0x554d1) [0x7f135316d4d1]
#21  /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/./libglib-2.0.so.0(g_main_context_iteration+0x31) [0x7f135316d571]
#22  0x7f135622d0e8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Core.so.5+0x5e
#23  0x7f13561fb019 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Core.so.5+0x187
#24  0x7f13561fee8f in QCoreApplication::exec() from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libQt5Core.so.5+0xfd
#25  0x7f135855e926 in Gui::Application::runApplication() from /tmp/.mount_FreeCAe7oSk3/usr/bin/../lib/libFreeCADGui.so+0x15f6
#26  /tmp/.mount_FreeCAe7oSk3/usr/bin/freecad(+0x44bf) [0x5617925604bf]
#27  /usr/lib/libc.so.6(__libc_start_main+0xd5) [0x7f1355cfcb25]
#28  /tmp/.mount_FreeCAe7oSk3/usr/bin/freecad(+0x47d9) [0x5617925607d9]
just in case it will be useful

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Post Reply