View Issue Details

IDProjectCategoryView StatusLast Update
0001656Slicer4Core: Scripting (Wrapping, Python)public2012-08-21 09:48
Reporterpieper Assigned Tojcfr  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionfixed 
Product VersionSlicer 4.0.1 
Target VersionSlicer 4.1.0Fixed in VersionSlicer 4.1.0 
Summary0001656: crash in scene clear coming from displayable manager destructor
Description

Exiting the program when there is a python scripted observer on the scene results in a crash.

Typically this would not be an error condition in VTK, because the RemoveAllObservers is called before a VTK object is deleted so no further event processing should happen on deleted classes. However in the example pasted below it seems that this processing is avoided when the object is a singleton.

Steps To Reproduce

Paste the code below into the python console to get the crash:

def x(a,b):
print(a,b)

slicer.mrmlScene.AddObserver('ModifiedEvent',x)
slicer.mrmlScene.Modified()
exit()

Additional Information

Here is the stack trace:

Program received signal SIGSEGV, Segmentation fault.
0x00007fffef345620 in PyDict_GetItem (op=0x4b9f710, key=0x7fffd16e83c0) at Objects/dictobject.c:631
631 if (!PyDict_Check(op))
(gdb) where
#0 0x00007fffef345620 in PyDict_GetItem (op=0x4b9f710, key=0x7fffd16e83c0) at Objects/dictobject.c:631
0000001 0x00007fffef345e0e in PyDict_GetItemString (v=0x4b9f710, key=<value optimized out>) at Objects/dictobject.c:2287
0000002 0x00007fffef3a5e92 in PyEval_EvalFrameEx (f=0x212e320, throwflag=<value optimized out>) at Python/ceval.c:1615
0000003 0x00007fffef3abd20 in PyEval_EvalCodeEx (co=0x16fb198, globals=<value optimized out>, locals=<value optimized out>, args=0x2, argcount=<value optimized out>,
kws=<value optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3000
0000004 0x00007fffef3320d0 in function_call (func=0x16fb230, arg=0x7fffd173b6c8, kw=0x0) at Objects/funcobject.c:524
0000005 0x00007fffef3050d3 in PyObject_Call (func=0x16fb230, arg=0x7fffd16e83c0, kw=0x0) at Objects/abstract.c:2492
0000006 0x00007fffef3a4153 in PyEval_CallObjectWithKeywords (func=0x16fb230, arg=0x7fffd173b6c8, kw=0x0) at Python/ceval.c:3619
0000007 0x00007fffebd5c610 in vtkPythonCommand::Execute (this=0x4c07d00, ptr=0x7d19b0, eventtype=33, CallData=0x0)
at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkPythonCommand.cxx:153
0000008 0x00007fffdf9ca53f in vtkSubjectHelper::InvokeEvent (this=0x858300, event=33, callData=0x0, self=0x7d19b0)
at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObject.cxx:602
0000009 0x00007fffdf9caa4f in vtkObject::InvokeEvent (this=0x7d19b0, event=33, callData=0x0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObject.cxx:770
0000010 0x00007fffdf9cac1e in vtkObject::Modified (this=0x7d19b0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObject.cxx:836
0000011 0x00007fffead0bbba in vtkMRMLScene::Clear (this=0x7d19b0, removeSingletons=1) at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/Core/vtkMRMLScene.cxx:495
0000012 0x00007fffead0ba58 in vtkMRMLScene::SceneCallback (clientData=0x7d19b0) at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/Core/vtkMRMLScene.cxx:448
0000013 0x00007fffdf8e4d79 in vtkCallbackCommand::Execute (this=0x7d1c50, caller=0x7d19b0, event=2, callData=0x0)
at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkCallbackCommand.cxx:42
0000014 0x00007fffdf9ca53f in vtkSubjectHelper::InvokeEvent (this=0x858300, event=2, callData=0x0, self=0x7d19b0)
at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObject.cxx:602
0000015 0x00007fffdf9caa4f in vtkObject::InvokeEvent (this=0x7d19b0, event=2, callData=0x0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObject.cxx:770
0000016 0x00007fffdf9cb264 in vtkObject::UnRegisterInternal (this=0x7d19b0, o=0x7a9780, check=0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObject.cxx:878
0000017 0x00007fffdf9ccbec in vtkObjectBase::UnRegister (this=0x7d19b0, o=0x7a9780) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObjectBase.cxx:182
0000018 0x00007fffeada033d in vtkObserverManager::SetObject (this=0x7a9780, nodePtr=0x866220, node=0x0)
at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/Core/vtkObserverManager.cxx:95
0000019 0x00007ffff1aafee2 in vtkMRMLAbstractLogic::SetMRMLSceneInternal (this=0x7b4e20, newScene=0x0)
at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/Logic/vtkMRMLAbstractLogic.cxx:249
0000020 0x00007ffff1aafe4e in vtkMRMLAbstractLogic::SetMRMLScene (this=0x7b4e20, newScene=0x0) at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/Logic/vtkMRMLAbstractLogic.cxx:235
0000021 0x00007ffff1aaf5d4 in ~vtkMRMLAbstractLogic (this=0x7b4e20, in_chrg=<value optimized out>)
at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/Logic/vtkMRMLAbstractLogic.cxx:109
0000022 0x00007ffff1ab1078 in ~vtkMRMLApplicationLogic (this=0x7b4e20, __in_chrg=<value optimized out>)
at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/Logic/vtkMRMLApplicationLogic.cxx:111
0000023 0x00007ffff207b79e in ~vtkSlicerApplicationLogic (this=0x7b4e20,
in_chrg=<value optimized out>)
---Type <return> to continue, or q <return> to quit---
at /home/pieper/slicer4/latest/Slicer4/Base/Logic/vtkSlicerApplicationLogic.cxx:282
0000024 0x00007fffdf9ccff7 in vtkObjectBase::UnRegisterInternal (this=0x7b4e20, check=0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObjectBase.cxx:279
0000025 0x00007fffdf9cb286 in vtkObject::UnRegisterInternal (this=0x7b4e20, o=0x0, check=0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObject.cxx:885
0000026 0x00007fffdf9ccbec in vtkObjectBase::UnRegister (this=0x7b4e20, o=0x0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObjectBase.cxx:182
0000027 0x00007fffdfa20d61 in ~vtkSmartPointerBase (this=0x6e1588, in_chrg=<value optimized out>)
at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkSmartPointerBase.cxx:62
0000028 0x00007ffff7318e56 in ~vtkSmartPointer (this=0x6e1588, __in_chrg=<value optimized out>) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkSmartPointer.h:27
0000029 0x00007ffff1de6d67 in ~vtkInternal (this=0x6e1570,
in_chrg=<value optimized out>)
at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/DisplayableManager/vtkMRMLDisplayableManagerFactory.cxx:45
0000030 0x00007ffff1de5b50 in ~vtkMRMLDisplayableManagerFactory (this=0x6e08e0, in_chrg=<value optimized out>)
at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/DisplayableManager/vtkMRMLDisplayableManagerFactory.cxx:79
0000031 0x00007ffff1de8b60 in ~vtkMRMLSliceViewDisplayableManagerFactory (this=0x6e08e0, __in_chrg=<value optimized out>)
at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/DisplayableManager/vtkMRMLSliceViewDisplayableManagerFactory.cxx:74
0000032 0x00007fffdf9ccff7 in vtkObjectBase::UnRegisterInternal (this=0x6e08e0, check=0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObjectBase.cxx:279
0000033 0x00007fffdf9cb286 in vtkObject::UnRegisterInternal (this=0x6e08e0, o=0x0, check=0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObject.cxx:885
0000034 0x00007fffdf9ccbec in vtkObjectBase::UnRegister (this=0x6e08e0, o=0x0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObjectBase.cxx:182
0000035 0x00007fffdf9cc96c in vtkObjectBase::Delete (this=0x6e08e0) at /home/pieper/slicer4/latest/Slicer4-superbuild/VTK/Common/vtkObjectBase.cxx:127
0000036 0x00007ffff1de8be1 in vtkMRMLSliceViewDisplayableManagerFactory::classFinalize ()
at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/DisplayableManager/vtkMRMLSliceViewDisplayableManagerFactory.cxx:82
0000037 0x00007ffff1de8cdc in ~vtkMRMLSliceViewDisplayableManagerFactoryInitialize (this=0x7ffff201f481,
in_chrg=<value optimized out>)
at /home/pieper/slicer4/latest/Slicer4/Libs/MRML/DisplayableManager/vtkMRMLSliceViewDisplayableManagerFactory.cxx:82
0000038 0x00007fffdde9d630 in __cxa_finalize () from /lib/libc.so.6
0000039 0x00007ffff1dac026 in __do_global_dtors_aux () from /home/pieper/slicer4/latest/Slicer4-superbuild/Slicer-build/bin/libMRMLDisplayableManager.so
0000040 0x0000000000000000 in ?? ()
(gdb)

TagsNo tags attached.

Activities

pieper

pieper

2012-01-19 09:49

administrator   ~0003507

Note that this issue is captured in the following test:

http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Applications/SlicerQT/Testing/Python/SlicerSceneObserverTest.py?view=markup

Which crashes on exit in the nightly tests:

http://slicer.cdash.org/testDetails.php?test=617216&amp;build=7900

finetjul

finetjul

2012-01-27 11:18

administrator   ~0003565

Same problem happens when exiting slicer after loading a volume via SampleData:

extract from SampleData.py:
storageNode = volumeNode.GetStorageNode()
if storageNode:
storageNode.AddObserver('ModifiedEvent', self.processStorageEvents)

Backtrace:
0 libpython2.6.dylib 0x0000000112b8082e PyErr_Fetch + 14 (errors.c:241)
1 libpython2.6.dylib 0x0000000112aedb55 instance_dealloc + 101 (classobject.c:636)
2 libpython2.6.dylib 0x0000000112af1431 instancemethod_dealloc + 129 (classobject.c:2366)
3 libvtkCommonPythonD.5.9.dylib 0x0000000112573e2b vtkPythonCommand::~vtkPythonCommand() + 319 (vtkPythonCommand.cxx:32)
4 libvtkCommon.5.9.dylib 0x000000011d7fc416 vtkCommand::UnRegister() + 102 (vtkCommand.cxx:135)
5 libvtkCommonPythonD.5.9.dylib 0x00000001125743ee vtkCommand::UnRegister(vtkObjectBase) + 28 (vtkCommand.h:220)
6 libvtkCommon.5.9.dylib 0x000000011d927f68 vtkObserver::~vtkObserver() + 58 (vtkObject.cxx:237)
7 libvtkCommon.5.9.dylib 0x000000011d9285a8 vtkSubjectHelper::RemoveAllObservers() + 68 (vtkObject.cxx:426)
8 libvtkCommon.5.9.dylib 0x000000011d928602 vtkObject::RemoveAllObservers() + 42 (vtkObject.cxx:763)
9 libvtkCommon.5.9.dylib 0x000000011d92a3dd vtkObject::UnRegisterInternal(vtkObjectBase
, int) + 1355 (vtkObject.cxx:885)
10 libvtkCommon.5.9.dylib 0x000000011d92da07 vtkObjectBase::UnRegister(vtkObjectBase*) + 47 (vtkObjectBase.cxx:183)
11 libMRMLCore.dylib 0x0000000113139112 vtkObserverManager::SetObject(vtkObject*, vtkObject) + 1378 (vtkObserverManager.cxx:104)
12 libMRMLCore.dylib 0x000000011313995c vtkObserverManager::SetAndObserveObject(vtkObject, vtkObject) + 592 (vtkObserverManager.cxx:118)
13 libMRMLCore.dylib 0x000000011308b5de vtkMRMLStorableNode::SetAndObserveStorageNodeID(char const
) + 162 (vtkMRMLStorableNode.cxx:390)
14 libMRMLCore.dylib 0x000000011308f515 vtkMRMLStorableNode::~vtkMRMLStorableNode() + 179 (vtkMRMLStorableNode.cxx:43)
15 libMRMLCore.dylib 0x0000000112e6fce3 vtkMRMLDisplayableNode::~vtkMRMLDisplayableNode() + 331 (vtkMRMLDisplayableNode.cxx:45)
16 libMRMLCore.dylib 0x000000011312f926 vtkMRMLVolumeNode::~vtkMRMLVolumeNode() + 202 (vtkMRMLVolumeNode.cxx:61)
17 libMRMLCore.dylib 0x0000000113014da9 vtkMRMLScalarVolumeNode::~vtkMRMLScalarVolumeNode() + 231 (vtkMRMLScalarVolumeNode.cxx:57)
18 libvtkCommon.5.9.dylib 0x000000011d92df2a vtkObjectBase::UnRegisterInternal(vtkObjectBase, int) + 288 (vtkObjectBase.cxx:279)
19 libvtkCommon.5.9.dylib 0x000000011d92a3f3 vtkObject::UnRegisterInternal(vtkObjectBase
, int) + 1377 (vtkObject.cxx:886)
20 libvtkCommon.5.9.dylib 0x000000011d92da07 vtkObjectBase::UnRegister(vtkObjectBase) + 47 (vtkObjectBase.cxx:183)
21 libMRMLCore.dylib 0x0000000113025dc2 vtkMRMLScene::RemoveNode(vtkMRMLNode
) + 3024 (vtkMRMLScene.cxx:1377)
22 libMRMLCore.dylib 0x0000000113026497 vtkMRMLScene::Clear(int) + 181 (vtkMRMLScene.cxx:472)
23 libMRMLCore.dylib 0x0000000113026621 vtkMRMLScene::SceneCallback(vtkObject, unsigned long, void, void) + 75 (vtkMRMLScene.cxx:447)
24 libvtkCommon.5.9.dylib 0x000000011d7f01ba vtkCallbackCommand::Execute(vtkObject
, unsigned long, void) + 82 (vtkCallbackCommand.cxx:43)
25 libvtkCommon.5.9.dylib 0x000000011d929c89 vtkSubjectHelper::InvokeEvent(unsigned long, void
, vtkObject) + 2579 (vtkObject.cxx:602)
26 libvtkCommon.5.9.dylib 0x000000011d929e75 vtkObject::InvokeEvent(unsigned long, void
) + 73 (vtkObject.cxx:770)
27 libvtkCommon.5.9.dylib 0x000000011d92a3d1 vtkObject::UnRegisterInternal(vtkObjectBase, int) + 1343 (vtkObject.cxx:881)
28 libvtkCommon.5.9.dylib 0x000000011d92da07 vtkObjectBase::UnRegister(vtkObjectBase
) + 47 (vtkObjectBase.cxx:183)
29 libMRMLCore.dylib 0x0000000113139112 vtkObserverManager::SetObject(vtkObject
, vtkObject) + 1378 (vtkObserverManager.cxx:104)
30 libMRMLLogic.dylib 0x000000010f354c26 vtkMRMLAbstractLogic::SetMRMLSceneInternal(vtkMRMLScene
) + 78 (vtkMRMLAbstractLogic.cxx:245)
31 libMRMLLogic.dylib 0x000000010f353e76 vtkMRMLAbstractLogic::SetMRMLScene(vtkMRMLScene) + 124 (vtkMRMLAbstractLogic.cxx:233)
32 libMRMLLogic.dylib 0x000000010f355888 vtkMRMLAbstractLogic::~vtkMRMLAbstractLogic() + 70 (vtkMRMLAbstractLogic.cxx:106)
33 libMRMLLogic.dylib 0x000000010f36a56b vtkMRMLApplicationLogic::~vtkMRMLApplicationLogic() + 121 (vtkMRMLApplicationLogic.cxx:111)
34 libSlicerBaseLogic.dylib 0x000000010efdc827 vtkSlicerApplicationLogic::~vtkSlicerApplicationLogic() + 2209 (vtkSlicerApplicationLogic.cxx:282)
35 libvtkCommon.5.9.dylib 0x000000011d92df2a vtkObjectBase::UnRegisterInternal(vtkObjectBase
, int) + 288 (vtkObjectBase.cxx:279)
36 libvtkCommon.5.9.dylib 0x000000011d92a3f3 vtkObject::UnRegisterInternal(vtkObjectBase, int) + 1377 (vtkObject.cxx:886)
37 libvtkCommon.5.9.dylib 0x000000011d92da07 vtkObjectBase::UnRegister(vtkObjectBase
) + 47 (vtkObjectBase.cxx:183)
38 libvtkCommon.5.9.dylib 0x000000011d9a4b83 vtkSmartPointerBase::~vtkSmartPointerBase() + 77 (vtkSmartPointerBase.cxx:64)
39 libqSlicerBaseQTGUI.dylib 0x000000010a39adaa vtkSmartPointer<vtkMRMLApplicationLogic>::~vtkSmartPointer() + 38 (vtkSmartPointer.h:27)
40 libMRMLDisplayableManager.dylib 0x000000010f20222d vtkMRMLDisplayableManagerFactory::vtkInternal::~vtkInternal() + 51 (vtkMRMLDisplayableManagerFactory.cxx:45)
41 libMRMLDisplayableManager.dylib 0x000000010f2006a1 vtkMRMLDisplayableManagerFactory::~vtkMRMLDisplayableManagerFactory() + 87 (vtkMRMLDisplayableManagerFactory.cxx:79)
42 libMRMLDisplayableManager.dylib 0x000000010f202f03 vtkMRMLThreeDViewDisplayableManagerFactory::~vtkMRMLThreeDViewDisplayableManagerFactory() + 65 (vtkMRMLThreeDViewDisplayableManagerFactory.cxx:74)
43 libvtkCommon.5.9.dylib 0x000000011d92df2a vtkObjectBase::UnRegisterInternal(vtkObjectBase, int) + 288 (vtkObjectBase.cxx:279)
44 libvtkCommon.5.9.dylib 0x000000011d92a3f3 vtkObject::UnRegisterInternal(vtkObjectBase
, int) + 1377 (vtkObject.cxx:886)
45 libvtkCommon.5.9.dylib 0x000000011d92da07 vtkObjectBase::UnRegister(vtkObjectBase*) + 47 (vtkObjectBase.cxx:183)
46 libvtkCommon.5.9.dylib 0x000000011d92d837 vtkObjectBase::Delete() + 45 (vtkObjectBase.cxx:128)
47 libMRMLDisplayableManager.dylib 0x000000010f202cdf vtkMRMLThreeDViewDisplayableManagerFactory::classFinalize() + 55 (vtkMRMLThreeDViewDisplayableManagerFactory.cxx:82)
48 libMRMLDisplayableManager.dylib 0x000000010f202db2 vtkMRMLThreeDViewDisplayableManagerFactoryInitialize::~vtkMRMLThreeDViewDisplayableManagerFactoryInitialize() + 70 (vtkMRMLThreeDViewDisplayableManagerFactory.cxx:82)
49 libMRMLDisplayableManager.dylib 0x000000010f202df9 tcf_1 + 41 (vtkMRMLThreeDViewDisplayableManagerFactory.h:72)
50 libsystem_c.dylib 0x00007fff945cd7c8
cxa_finalize + 274
51 libsystem_c.dylib 0x00007fff945cd652 exit + 18
52 0x0000000109fc4d2b start + 59

finetjul

finetjul

2012-01-27 11:21

administrator   ~0003566

In that previous case, it might be because the Sample Data is uninstantiated before the scene is cleared.
Therefore the PyObject has already been deleted.

=> when a python module (or all python) is unloaded, the observers should probably be removed automatically.

jcfr

jcfr

2012-01-27 11:33

administrator   ~0003567

Seems there is an AddObserver [1] and its corresponding remove observer [2]

Where you talking about something different ?

[1] https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/Scripts/SampleData.py#L132
[2] https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/Scripts/SampleData.py#L151

finetjul

finetjul

2012-01-27 11:41

administrator   ~0003568

You're right, and indeed, the RemoveObserver is never called when the image is locale:

Status: Idle
Requesting download MRHead from http://www.slicer.org/slicerWiki/images/4/43/MR-head.nrrd...
Displaying...
finished.
Status: Idle

Steve, can you review processStorageEvents, checking the state of the node doesn't seem ideal (or maybe the state should be fixed.

jcfr

jcfr

2012-03-21 00:45

administrator   ~0003897

See http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=19669

jcfr

jcfr

2012-07-27 15:20

administrator   ~0005297

Closing resolved issues that have not been updated in more than 2 months.

Issue History

Date Modified Username Field Change
2012-01-19 09:37 pieper New Issue
2012-01-19 09:37 pieper Status new => assigned
2012-01-19 09:37 pieper Assigned To => jcfr
2012-01-19 09:49 pieper Note Added: 0003507
2012-01-19 09:55 finetjul Category Base Code => Scripting
2012-01-27 11:18 finetjul Note Added: 0003565
2012-01-27 11:21 finetjul Note Added: 0003566
2012-01-27 11:22 finetjul Product Version => Slicer 4.0.1
2012-01-27 11:33 jcfr Note Added: 0003567
2012-01-27 11:41 finetjul Note Added: 0003568
2012-03-21 00:45 jcfr Note Added: 0003897
2012-03-21 00:45 jcfr Status assigned => resolved
2012-03-21 00:45 jcfr Fixed in Version => Slicer 4.1.0
2012-03-21 00:45 jcfr Resolution open => fixed
2012-07-27 15:20 jcfr Note Added: 0005297
2012-07-27 15:20 jcfr Status resolved => closed
2012-08-21 09:48 jcfr Target Version => Slicer 4.1.0