Greetings All-Knowing PyQters,<div>I have a strange bug that's causing segmentation faults in my program. I have identified some of the key contributors to the bug and a workaround, but I would love for someone to explain what causes the crash so I can avoid similar problems in the future. </div>
<div><br></div><div>Here are the things required to cause the crash:</div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>1) Repeatedly creating and deleting a GraphicsView and GraphicsItem</div><div>
2) The each GraphicsItem has a reference to the GraphicsView it is shown in</div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>3) Having a second thread running and actively working</div><div><br>
</div><div>Usually a segmentation fault will occur after roughly 10-1000 create/delete cycles. Taking away any of these components prevents the crash. The second thread does not have to be doing anything specific and does not even have to be a QThread; it just has to be doing _something_. If the Item has a weakref to its View, there is no crash (and this is a perfectly acceptable workaround). </div>
<div><br></div><div>I have attached a GDB backtrace and a short script demonstrating the bug. When I run the script on my system (Ubuntu 10.04, PyQt 4.7.2), about half of the time it causes a segfault, and the rest of the time it just freezes. I've also tested the script on WinXp with PyQt 4.8.3 and 4.5.4, with similar results. PySide does not have the bug, so I suspect it is not a Qt issue. </div>
<div><br></div><div>Any advice would be greatly appreciated!</div><div><br></div><div>Luke</div>