Crash when editing draft line

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
hko
Posts: 105
Joined: Thu Apr 23, 2020 10:44 pm

Crash when editing draft line

Post by hko »

Steps to reproduce (many details probably irrelevant but this is how I did it):
1. Create a new document.
2. Switch to Draft workbench and select Top view
3. Add a horizontal draft line
4. Double click the created object in the tree view
5. Select the leftmost point of the line with mouse
6. Restrict change to just x coordinate with shift and move cursor to task dialog and select the "Local delta X" input
7. Enter a positive value that moves the endpoint a little bit to the right and hit return.
8. Observe that FreeCAD crashes. Stacktrace below. In fact, two stacktraces from two different attempts, with a small difference.

The problem cannot be reproduced by moving the line endpoint with mouse, you need to enter the delta X value to the dialog.

Stacktrace from one attempt:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
#0  /lib/x86_64-linux-gnu/libc.so.6(+0x43090) [0x151bd36fb090]
#1  0x151bd14da376 in QQmlData::isSignalConnected(QAbstractDeclarativeData*, QObject const*, int) from /lib/x86_64-linux-gnu/libQt5Qml.so.5+0x6
#2  0x151bd3d58a6e in QMetaObject::activate(QObject*, int, int, void**) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x6e
#3  0x151bd489ac8d in QWidgetLineControl::processKeyEvent(QKeyEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x2cd
#4  0x151bd488d99f in QLineEdit::keyPressEvent(QKeyEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x1f
#5  0x151bd7f5dfe2 in Gui::InputField::keyPressEvent(QKeyEvent*) from /usr/local/freecad/lib/libFreeCADGui.so+0x382
#6  0x151bd478a77d in QWidget::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x74d
#7  0x151bd4893d32 in QLineEdit::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0xb2
#8  0x151bd4747a66 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x86
#9  0x151bd475181e in QApplication::notify(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0xa5e
#10  0x151bd794914a in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/local/freecad/lib/libFreeCADGui.so+0x112
#11  0x151bd3d2d80a in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x18a
#12  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x1cc216) [0x151bd47a9216]
#13  0x151bd4747a66 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x86
#14  0x151bd47510f0 in QApplication::notify(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x330
#15  0x151bd794914a in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/local/freecad/lib/libFreeCADGui.so+0x112
#16  0x151bd3d2d80a in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x18a
#17  0x151bd4114b2b in QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0x16b
#18  0x151bd411a0f1 in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0x241
#19  0x151bd40f435b in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0xbb
#20  /lib/x86_64-linux-gnu/libQt5XcbQpa.so.5(+0x7932e) [0x151bcd73f32e]
#21  /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x27d) [0x151bd19d917d]
#22  /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x52400) [0x151bd19d9400]
#23  /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x33) [0x151bd19d94a3]
#24  0x151bd3d85435 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x65
#25  0x151bd3d2c3ab in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x12b
#26  0x151bd3d34116 in QCoreApplication::exec() from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x96
#27  0x151bd77f5956 in Gui::Application::runApplication() from /usr/local/freecad/lib/libFreeCADGui.so+0x28f2
#28  /usr/local/freecad/bin/FreeCAD(+0x12987) [0x55fccbdbe987]
#29  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x151bd36dc083]
#30  /usr/local/freecad/bin/FreeCAD(+0x11c2e) [0x55fccbdbdc2e]
Stacktrace from another attempt:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
#0  /lib/x86_64-linux-gnu/libc.so.6(+0x43090) [0x151351a68090]
#1  0x1513520c5a32 in QMetaObject::activate(QObject*, int, int, void**) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x32
#2  0x151352c07c8d in QWidgetLineControl::processKeyEvent(QKeyEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x2cd
#3  0x151352bfa99f in QLineEdit::keyPressEvent(QKeyEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x1f
#4  0x1513562cafe2 in Gui::InputField::keyPressEvent(QKeyEvent*) from /usr/local/freecad/lib/libFreeCADGui.so+0x382
#5  0x151352af777d in QWidget::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x74d
#6  0x151352c00d32 in QLineEdit::event(QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0xb2
#7  0x151352ab4a66 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x86
#8  0x151352abe81e in QApplication::notify(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0xa5e
#9  0x151355cb614a in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/local/freecad/lib/libFreeCADGui.so+0x112
#10  0x15135209a80a in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x18a
#11  /lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x1cc216) [0x151352b16216]
#12  0x151352ab4a66 in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x86
#13  0x151352abe0f0 in QApplication::notify(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x330
#14  0x151355cb614a in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/local/freecad/lib/libFreeCADGui.so+0x112
#15  0x15135209a80a in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x18a
#16  0x151352481b2b in QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0x16b
#17  0x1513524870f1 in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0x241
#18  0x15135246135b in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /lib/x86_64-linux-gnu/libQt5Gui.so.5+0xbb
#19  /lib/x86_64-linux-gnu/libQt5XcbQpa.so.5(+0x7932e) [0x15134baac32e]
#20  /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x27d) [0x15134fd4617d]
#21  /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x52400) [0x15134fd46400]
#22  /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x33) [0x15134fd464a3]
#23  0x1513520f2435 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x65
#24  0x1513520993ab in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x12b
#25  0x1513520a1116 in QCoreApplication::exec() from /lib/x86_64-linux-gnu/libQt5Core.so.5+0x96
#26  0x151355b62956 in Gui::Application::runApplication() from /usr/local/freecad/lib/libFreeCADGui.so+0x28f2
#27  /usr/local/freecad/bin/FreeCAD(+0x12987) [0x55f99d5fd987]
#28  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x151351a49083]
#29  /usr/local/freecad/bin/FreeCAD(+0x11c2e) [0x55f99d5fcc2e]

Code: Select all

OS: Ubuntu 20.04.5 LTS (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: recent master, see hash
Build type: Debug
Branch: master
Hash: c6c1c46ca04edf5f923180acf05aeb5f7b0dca5f
Python 3.8.10, Qt 5.12.8, Coin 4.0.0, Vtk 7.1.1, OCC 7.3.0
Locale: English/United States (en_US)
Installed mods: 
  * 3DfindIT 1.2.0
  * Render 2022.2.0
  * BIM 2021.12.0
  * Reinforcement
  * Manipulator 1.4.9
  * Assembly4.backup1662941442.2770898
  * parts_library
  * Assembly4 0.12.4
  * fasteners 0.4.15
  * dodo
User avatar
Roy_043
Veteran
Posts: 8541
Joined: Thu Dec 27, 2018 12:28 pm

Re: Crash when editing draft line

Post by Roy_043 »

Can't confirm.

Code: Select all

OS: Windows 8.1 Version 6.3 (Build 9600)
Word size of FreeCAD: 64-bit
Version: 0.21.30716 (Git)
Build type: Release
Branch: master
Hash: cbd19631428f1d9eb4faae30220551608a648589
Python 3.8.13, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: Dutch/Netherlands (nl_NL)
Installed mods: 
User avatar
ragohix769
Posts: 568
Joined: Sat Jul 18, 2020 7:04 am
Location: Rome - Italy

Re: Crash when editing draft line

Post by ragohix769 »

I tried to replicate, but my FC don't crash, I don't know exactly how troubleshooting this.

Code: Select all

OS: Ubuntu 20.04.5 LTS (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: 0.21.
Build type: Release
Branch: unknown
Hash: 7c51aa9749eddcfc0981feea3c3468560b88db22
Python 3.8.10, Qt 5.12.8, Coin 4.0.0, Vtk 7.1.1, OCC 7.5.2
Locale: Italian/Italy (it_IT)
Installed mods: 
  * FreeCAD-BlenderBIM 2022.10.20
  * BIM 2021.12.0
After #ElonMuskBuyTwitter I'm no more on Twitter, that's really enough :-(
=> Now you can find me here on #Mastodon: https://mastodon.uno/@opensoul - I hope more people do the same :-)
hko
Posts: 105
Joined: Thu Apr 23, 2020 10:44 pm

Re: Crash when editing draft line

Post by hko »

Thanks for testing. I had a chance to test on another machine (with the same OS version) and I couldn't reproduce the problem either. I suspected a clean build might help on the original test machine but surprisingly that was not the case. Nevertheless, evidence points to it being a "local" problem on that one machine. I need to check one more time if the clean build was really clean and didn't have ccache in use or something like that.
hko
Posts: 105
Joined: Thu Apr 23, 2020 10:44 pm

Re: Crash when editing draft line

Post by hko »

I bisected the problem to commit fc14567d3424e19e8a3a7d333e253f46214ca469 by @Roy_043.

Edit.endEditing in Mod/Draft/draftguitools/gui_edit.py calls DraftToolBar.editUi and before that commit editUi called self.taskUi which did this (partial copy&paste):

Code: Select all

            self.isTaskOn = True
            todo.delay(FreeCADGui.Control.closeDialog,None)
            self.baseWidget = DraftBaseWidget()
            self.layout = QtGui.QVBoxLayout(self.baseWidget)
            self.setupToolBar(task=True)
            self.retranslateUi(self.baseWidget)
            self.panel = DraftTaskPanel(self.baseWidget,extra)
            todo.delay(FreeCADGui.Control.showDialog,self.panel)
Now editUi calls self.makeDumbTask which does this (class TaskPanel definition not included):

Code: Select all

        FreeCADGui.Control.closeDialog()
        panel = TaskPanel(extra, on_close_call)
        FreeCADGui.Control.showDialog(panel)
So, observe that both the old code and the new close the current dialog and show a new one. However, the old code does both of those things using the todo.delay mechanism.

According to git blame, todo.delay was added to taskUi's closeDialog/showDialog calls by @yorik in 2011 in commit 3784de7c7692e3e30deb75110349eb9c35682a31 with a description "+ fixed bugs when entering manual coords in Draft Taskview mode".

If I modify makeDumbTask so that closeDialog and showDialog are called via todo.delay, I can no longer reproduce the crash when running FreeCAD normally. However, I was still able to reproduce it when running under a debugger (with breakpoint-logging in a keypress processing method). Seems to be timing sensitive and while todo.delay helps, it's not a proper fix. Even with unmodifed code, the crash didn't always happen on the first attempt. Those of you who tried to reproduce this, you used Release builds. I have a Debug build which is slower. Perhaps that's why I can reproduce this and you can't. I'll try making a release build and see if that makes it harder to reproduce for me as well.

I suppose Yorik no longer remembers anything about those bugs after such a long time? I wonder if this change has reintroduced at least one of them.
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Crash when editing draft line

Post by yorik »

hko wrote: Sun Nov 06, 2022 10:49 pm I suppose Yorik no longer remembers anything about those bugs after such a long time?
I don't :D

the todo system in draft was made just for that... Sometimes a condition occurs where QT stuff is changed or removed in Python while it is still needed by other Qt functionality, which results in a crash. These are hard to detect and trace back. The "official way" is to let Qt handle everything in its own time, and that is done usually by using those timer mechanisms, which let Qt process all its queue before it does what we need to be done..
hko
Posts: 105
Joined: Thu Apr 23, 2020 10:44 pm

Re: Crash when editing draft line

Post by hko »

Issue here and mitigation pull request here.

Another report about the same problem here.
Post Reply