2nd eventFilter crashes FreeCad

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
KAKM
Posts: 109
Joined: Tue May 04, 2021 12:17 am

2nd eventFilter crashes FreeCad

Post by KAKM »

If I create an eventFilter, delete it, and then create a second eventFilter, FreeCAD crashes. It doesn't matter whether I use the delete_recorder() function or simply reload the file. The problem is likely somewhere in the filter handling (since it initializes fine), but it isn't crashing for every event coming through, just some of them, and as far as I can tell, it isn't associated with any single type or number of events. The most consistent way to cause the crash that I've found is this:

Code: Select all

import TutorialUi
recorder=TutorialUi.CommandSelection.record_commands
TutorialUi.delete_recorder
recorder2=TutorialUi.CommandSelection.record_commands
The keyrelease (or keypress if you hold it) after pressing enter on the first recorder will cause a crash about 25% of the time, but the same keypress/release for the second one is close enough to 100% that I can't recall an exception.

Any ideas for a workaround? I strongly suspect the bug causing this is somewhere in the Qt.

The FreeCAD terminal window says that it's Segmentation Fault: 11, and the Apple bug report said it was code 0xb in the SIGNAL namespace.

Code: Select all

OS: macOS 10.15
Word size of FreeCAD: 64-bit
Version: 0.20.28901 +1 (Git)
Build type: Release
Branch: ipatch.builds.git.master.head.may10
Hash: 778a95f27e26e040ff29599847a224d44b7a5fa7
Python 3.10.4, Qt 5.15.3, Coin 4.0.1, OCC 7.5.3
Locale: English/United States (en_US)
Installed mods: 
  * Tutorial-dev
  * CfdOF 1.16.3
Attachments
TutorialUi.py
(7.14 KiB) Downloaded 11 times
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: 2nd eventFilter crashes FreeCad

Post by openBrain »

KAKM wrote: Sun Jul 10, 2022 12:35 am Any ideas for a workaround? I strongly suspect the bug causing this is somewhere in the Qt.
There are known crashes on some configurations/situations in PySide when installing an eventFilter directly on the QApplication.
What you can try is to install it on the QMainWindow. It won't crash but most probably you will miss some events that you need.

I just opened your code (didn't run it yet) and there are 2 issues.

On L184, your 'Observer()' should be called using a parent like 'Observer(FreeCADGui.getMainWindow())'. This isn't strictly needed, but it avoid lot of problems, like the one you describe in comment.

On L66-67 you have overridden the '__del__' method of your class, but you forgot to call the superclass method.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: 2nd eventFilter crashes FreeCad

Post by openBrain »

Try to test your code
ModuleNotFoundError: No module named 'TutorialClasses'
KAKM
Posts: 109
Joined: Tue May 04, 2021 12:17 am

Re: 2nd eventFilter crashes FreeCad

Post by KAKM »

Shoot. I thought that wasn't a direct dependency because it wasn't barfing if I didn't import it. Sorry about that.

I'll give QMainWindow a try and see if it'll get a high enough percentage of events to be a viable option, fix those other couple issues, and see what happens.
Attachments
TutorialClasses.py
(3.52 KiB) Downloaded 8 times
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: 2nd eventFilter crashes FreeCad

Post by openBrain »

KAKM wrote: Sun Jul 10, 2022 12:35 am The most consistent way to cause the crash that I've found is this:

Code: Select all

import TutorialUi
recorder=TutorialUi.CommandSelection.record_commands
TutorialUi.delete_recorder
recorder2=TutorialUi.CommandSelection.record_commands
OK, I guess this is incorrect calls, and this should be something like :

Code: Select all

import TutorialUi
recorder=TutorialUi.CommandSelection.record_commands() # call a function
TutorialUi.delete_recorder(recorder) # tell which recorder to delete
recorder2=TutorialUi.CommandSelection.record_commands() # call a function
Correct ?
KAKM
Posts: 109
Joined: Tue May 04, 2021 12:17 am

Re: 2nd eventFilter crashes FreeCad

Post by KAKM »

openBrain wrote: Wed Jul 13, 2022 10:41 amCorrect ?
That is, in fact, exactly what I had intended to put in that post, but evidently failed to do.

I did try switching to applying the event filter to the main window. It seemed to ignore all my mouse clicks, but crashes as soon as I pressed a key.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: 2nd eventFilter crashes FreeCad

Post by openBrain »

Here I can't run because I'm missing a UI file needed in the code.
KAKM
Posts: 109
Joined: Tue May 04, 2021 12:17 am

Re: 2nd eventFilter crashes FreeCad

Post by KAKM »

https://github.com/kaakmal/tutorial-wor ... rInterface
Here, so that I don't forget something stupid yet again. It's a bit out of date (git push is not behaving itself), but any supporting files should be new enough to at least let things run.
Post Reply