-
jcfr authored
How to reproduce: 1. Go to endoscopy module (just an example, the behavior is the same for every scripted modules) 2. Copy-paste this into the Python console: import sys for i in range(30): w = slicer.modules.endoscopy.widgetRepresentation().self() print("Reference count of widget object: "+str(sys.getrefcount(w))) => memory is corrupted now and Slicer will crash very soon (e.g., if the above code copy-pasted again or any other operation is performed) Problem: Each time pythonSelf() is used to return an reference to Python, the reference count is decreased by one (when the temporary Python object is deleted). Solution: When returning a reference to Python, the reference count has to be increased by one. (for example, the same is done in CTK-build\PythonQt\tests\PythonQtTests.h) This might (hopefully) also solve the frequent crash of Slicer on application exit due to double-delete of PythonQt widgets. Reviewed-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com> Reviewed-by: Max Smolens <max.smolens@kitware.com> From: Andras Lasso <lasso@queensu.ca> git-svn-id: http://svn.slicer.org/Slicer4/trunk@24833 3bd1e089-480b-0410-8dfb-8563597acbee
0ac807fb