Description
I have got two situations where C++ Qt deletes some object and creates new one on the same address later, but the wrapper wasn't removed from WrapperMapper. When PySide wanted to retrieve wrapper fro the new cptr, it already found one in wrapper mapper sometimes with completely different class causing crashes.
I'm attaching two patches to fix those issues
Patch 1 : this was sadly long time ago, so I don't exactly remember what was directly happening, but my code was generating a lot of QSocket objects and eventually addresses got reused and crash happened. Also the crash was happening only on embedded PySide inside Autodesk 3dsMax, but this patch fixed the crash and didn't cause any problems, so it mght be worth integrating it.
Patch 2 : when moving widgets between parents, Qt in the background gets QWidgetItem instances and manually deletes them. But if QWidgetItem was previously requested by PySide the wrapper was not being deleted and was pointing to invalid cptr. Eventually this cptr was replaced by new instance, and when wrapper has been requested for the cptr, the wrapper for QWidgetItem was returned ( in my case, one of my eventFilters was receiving QWidgetItem instance instead of QEvent) The fix was to use same logic as Qt to determine the QwidgetITem to be deleted and delete wrapper manually on every occasion it is deleted in the C++.