[QGIS-Developer] pyqgis QgsGeometrySnapper does not snap to a source created inside a function

Gabriel De Luca pablogabrieldeluca at gmail.com
Fri Oct 20 06:32:43 PDT 2023


Thank you both Germán and David,

  Original code didn't crashed a QGIS 3.28.11 here, but it seemed to work
silently with an empty reference layer.


Regards,
Gabriel

El vie, 20 oct 2023 a la(s) 10:23, Germán Carrillo (
carrillo.german at gmail.com) escribió:

> *> The underlying C++ code expects a pointer to the reference layer. If
> the python wrapper just passes the pointer of the object that was created
> in the call, the object will be out of scope after the function call
> returns and will be garbage collected. Someone who actually knows the code
> details can verify or contradict this.*
>
> This makes sense to me.
> In fact, the original code makes QGIS crash (using v3.28.6) with a
> Segmentation Fault, indicating that the underlying C++ object has been
> deleted.
> That's why you should first create a Python variable to make it clear that
> the layer object should persist in the outer scope.
>
> Regards,
>
> Germán
>
>
> El vie, 20 oct 2023 a las 5:30, David Strip (<qgis-user at stripfamily.net>)
> escribió:
>
>> On 10/19/2023 10:32 AM, Gabriel De Luca via QGIS-Developer wrote:
>>
>> Hi German,
>>
>>   Thanks. Yes, it works that way. Do you know why?
>>
>>
>> Regards,
>> Gabriel
>>
>>
>> Since nobody who really knows the code has responded yet, I'll conjecture
>> it's a scoping issue. The underlying C++ code expects a pointer to the
>> reference layer. If the python wrapper just passes the pointer of the
>> object that was created in the call, the object will be out of scope after
>> the function call returns and will be garbage collected. Someone who
>> actually knows the code details can verify or contradict this.
>>
>
>
> --
> -----------
>    |\__
> (:>__)(
>    |/
> Soluciones Geoinformáticas Libres
> http://geotux.tuxfamily.org/
> https://twitter.com/GeoTux2 <http://twitter.com/GeoTux2>
>
> <http://gis.stackexchange.com/users/4972/germ%c3%a1n-carrillo>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231020/3bfaa482/attachment-0001.htm>


More information about the QGIS-Developer mailing list