FC crash with SoNodeSensor

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

FC crash with SoNodeSensor

Post by Chris_G »

Hi,
I am experimenting with coin sensors.
Starting from this example : https://github.com/looooo/pivy/blob/mas ... eSensor.py
I slightly modified it to work in FC's 3D view :

Code: Select all

#!/usr/bin/env python

###
# Copyright (c) 2002-2007 Systems in Motion
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

###
# This is an example from the Inventor Mentor,
# chapter 12, example 2.
#
# Using getTriggerNode/getTriggerField methods of the data
# sensor.
#

import sys

from pivy.coin import *

# Sensor callback function:
def rootChangedCB(void, mySensor):
    # Sensors get autocasted; there is no need to cast them manually
    # through the cast() function, such as:
    #   mySensor = cast(s, "SoDataSensor")
    # mySensor is therefore a SoNodeSensor.

    changedNode = mySensor.getTriggerNode()
    changedField = mySensor.getTriggerField()
    
    print("The node named '%s' changed" % (changedNode.getName().getString()))

    if changedField:
        # the pythonic getFieldName() method returns a string or None in Pivy.
        fieldName = changedNode.getFieldName(changedField)
        print(" (field %s)" % (fieldName))
    else:
        print(" (no fields changed)")


# SoDB.init() invoked automatically upon coin module import

root = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
#root.setName("Root")

myCube = SoCube()
root.addChild(myCube)
myCube.setName("MyCube")

mySphere = SoSphere()
root.addChild(mySphere)
mySphere.setName("MySphere")

mySensor = SoNodeSensor(rootChangedCB, None)
mySensor.setPriority(0)
# mySensor.setFunction(rootChangedCB)
mySensor.attach(root)

# Now, make a few changes to the scene graph the sensor's
# callback function will be called immediately after each
# change.
myCube.width = 1.0
myCube.height = 2.0
mySphere.radius = 3.0
root.removeChild(mySphere)

It works fine so far.
Now, if I add an object in the document ( a Part.Box for example ), then FC crashes :

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
#0  /lib/x86_64-linux-gnu/libc.so.6(+0x357f0) [0x7f659637c7f0]
#1  /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyObject_Call+0x2a) [0x7f6597f6a53a]
#2  /usr/lib/python2.7/dist-packages/pivy/_coin.x86_64-linux-gnu.so(+0x20cca0) [0x7f6557656ca0]
#3  /usr/lib/python2.7/dist-packages/pivy/_coin.x86_64-linux-gnu.so(+0x237190) [0x7f6557681190]
#4  0x7f6595d4d1a9 in SoDataSensor::trigger() from /usr/lib/x86_64-linux-gnu/libCoin.so.80+0x9
#5  0x7f6595d4e722 in SoSensorManager::processImmediateQueue() from /usr/lib/x86_64-linux-gnu/libCoin.so.80+0xa2
#6  0x7f6595bcab95 in SoDB::endNotify() from /usr/lib/x86_64-linux-gnu/libCoin.so.80+0x35
#7  0x7f6595b3ccbd in SoField::valueChanged(int) from /usr/lib/x86_64-linux-gnu/libCoin.so.80+0x6d
#8  0x7f6599189bae in Gui::ViewProvider::hide() from /usr/lib/freecad-daily/lib/libFreeCADGui.so+0x3e
#9  0x7f6599189db0 in Gui::ViewProvider::update(App::Property const*) from /usr/lib/freecad-daily/lib/libFreeCADGui.so+0x50
#10  0x7f6598f20ca3 in Gui::Document::slotChangedObject(App::DocumentObject const&, App::Property const&) from /usr/lib/freecad-daily/lib/libFreeCADGui.so+0x43
#11  0x7f6598876c03 in boost::signal2<void, App::DocumentObject const&, App::Property const&, boost::last_value<void>, int, std::less<int>, boost::function<void (App::DocumentObject const&, App::Property const&)> >::operator()(App::DocumentObject const&, App::Property const&) from /usr/lib/freecad-daily/lib/libFreeCADApp.so+0x4c3
#12  0x7f659888ca21 in App::DocumentObject::onChanged(App::Property const*) from /usr/lib/freecad-daily/lib/libFreeCADApp.so+0x21
#13  0x7f655f0f53ff in Part::Feature::onChanged(App::Property const*) from /usr/lib/freecad-daily/lib/Part.so+0x4f
#14  0x7f655f0ff051 in Part::Primitive::onChanged(App::Property const*) from /usr/lib/freecad-daily/lib/Part.so+0x111
#15  0x7f65988f6c75 in App::Property::hasSetValue() from /usr/lib/freecad-daily/lib/libFreeCADApp.so+0x35
#16  0x7f655f0d0f39 in Part::Box::execute() from /usr/lib/freecad-daily/lib/Part.so+0x159
#17  0x7f659888a485 in App::DocumentObject::recompute() from /usr/lib/freecad-daily/lib/libFreeCADApp.so+0x15
#18  0x7f655f0f529f in Part::Feature::recompute() from /usr/lib/freecad-daily/lib/Part.so+0x1f
#19  0x7f65988584c4 in App::Document::_recomputeFeature(App::DocumentObject*) from /usr/lib/freecad-daily/lib/libFreeCADApp.so+0xb4
#20  0x7f659885fc2f in App::Document::recompute() from /usr/lib/freecad-daily/lib/libFreeCADApp.so+0x4df
#21  0x7f65990e0a33 in Gui::PropertyEditor::PropertyEditor::closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint) from /usr/lib/freecad-daily/lib/libFreeCADGui.so+0x63
#22  0x7f6596e4bf70 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x4d0
#23  0x7f6597a11000 in QAbstractItemDelegate::closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x50
#24  0x7f65978ef5ce in QItemDelegate::eventFilter(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x27e
#25  0x7f6596e37a16 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x86
#26  0x7f659736401c in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x6c
#27  0x7f659736af76 in QApplication::notify(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x2b6
#28  0x7f6598f3ddc4 in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/lib/freecad-daily/lib/libFreeCADGui.so+0x54
#29  0x7f6596e378ad in QCoreApplication::notifyInternal(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x8d
#30  0x7f6597368e2f in QApplicationPrivate::setFocusWidget(QWidget*, Qt::FocusReason) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x1af
#31  0x7f65973b5ceb in QWidget::setFocus(Qt::FocusReason) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x1cb
#32  0x7f659736b01c in QApplication::notify(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x35c
#33  0x7f6598f3ddc4 in Gui::GUIApplication::notify(QObject*, QEvent*) from /usr/lib/freecad-daily/lib/libFreeCADGui.so+0x54
#34  0x7f6596e378ad in QCoreApplication::notifyInternal(QObject*, QEvent*) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x8d
#35  0x7f659736a73d in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x14d
#36  /usr/lib/x86_64-linux-gnu/libQtGui.so.4(+0x249452) [0x7f65973e8452]
#37  0x7f65973e7ce3 in QApplication::x11ProcessEvent(_XEvent*) from /usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x16b3
#38  /usr/lib/x86_64-linux-gnu/libQtGui.so.4(+0x272592) [0x7f6597411592]
#39  /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x2a7) [0x7f658fa9b377]
#40  /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x4a5e0) [0x7f658fa9b5e0]
#41  /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x2c) [0x7f658fa9b68c]
#42  0x7f6596e6820e in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x7e
#43  /usr/lib/x86_64-linux-gnu/libQtGui.so.4(+0x272666) [0x7f6597411666]
#44  0x7f6596e3612f in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x3f
#45  0x7f6596e36495 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x1b5
#46  0x7f6596e3c459 in QCoreApplication::exec() from /usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x99
#47  0x7f6598ef6c02 in Gui::Application::runApplication() from /usr/lib/freecad-daily/lib/libFreeCADGui.so+0x15e2
#48  freecad-daily(main+0x661) [0x560d8e7180e1]
#49  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1) [0x7f65963673f1]
#50  freecad-daily(_start+0x2a) [0x560d8e7192fa]
Am I doing something wrong, or is it a FC bug ?
Thanks,
Chris
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: FC crash with SoNodeSensor

Post by looo »

seems to work with the pivy-branch I am using. (At least no crash)
I have added some of these fixes to my branch recently... https://github.com/looooo/pivy
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: FC crash with SoNodeSensor

Post by Chris_G »

Thanks looo,
I just installed your pivy fork and it works now.
Any chance your work on pivy goes into official pivy master ?
Chris
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: FC crash with SoNodeSensor

Post by looo »

I have already asked at the coin mailing list if there is a chance to merge my branch into the official pivy branch. But I don't think this will happen soon.


At the moment there are some more issues to be resolved, but once this is done, I will try to create a 0.6.x release for pivy.
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: FC crash with SoNodeSensor

Post by Chris_G »

OK. Thanks.
Post Reply