[Qgis-developer] QgsRubberBand RuntimeError: underlying C/C++ object has been deleted

Martin Dobias wonder.sk at gmail.com
Thu Feb 13 20:07:52 PST 2014


Hi Vincent

On Fri, Feb 14, 2014 at 2:17 AM, Vincent Mora <vincent.mora at oslandia.com> wrote:
>
> I found that a bit surprising, so I did the test, an actually python+sip do
> a pretty good job in ref counting (at least for the mentioned classes which
> are pretty simple)
>
> I Added a dtor to QgsSnappingResult to see when it's called:
>
> ~QgsSnappingResult(){std::cout << __PRETTY_FUNCTION__ << "\n";}
>
>
> And the little script:
>
> from qgis.core import *
>
> print "try to del r while p is still referencing one of it's members"
> r = QgsSnappingResult()
> p = r.snappedVertex
> del r
> print "it's not deleted yet"
> print "delete the referencing guy"
> del p
> print "it's deleted"
>
> print "try to del r (i.e. without anyone referencing anything)"
> r = QgsSnappingResult()
> del r
> print "it's deleted"

This reference counting must be a new feature in more recent versions
of SIP: in QGIS with 32-bit OSGeo4W (with SIP 4.12.1) I am getting the
behavior I described earlier, with invalid "snappedVertex" after
deletion of the owning instance. It is also possible to check it with
sys.getrefcount(r) before deleting it - on windows I get 2 (one from
"r" and one for being used in the getrefcount), while on linux (with
SIP 4.15.2) it reports 3 (obviously one more for reference from "p").

Cheers
Martin


More information about the Qgis-developer mailing list