<div dir="ltr"><div>Thank you both Germán and David,</div><div><br></div><div>  Original code didn't crashed a QGIS 3.28.11 here, <span class="gmail-HwtZe" lang="en"><span class="gmail-jCAhz gmail-ChMk0b"><span class="gmail-ryNqvb">but it seemed to work silently with an empty reference layer.</span></span></span></div><div><span class="gmail-HwtZe" lang="en"><span class="gmail-jCAhz gmail-ChMk0b"><span class="gmail-ryNqvb"><br></span></span></span></div><div><span class="gmail-HwtZe" lang="en"><span class="gmail-jCAhz gmail-ChMk0b"><span class="gmail-ryNqvb"><br></span></span></span></div><div><span class="gmail-HwtZe" lang="en"><span class="gmail-jCAhz gmail-ChMk0b"><span class="gmail-ryNqvb">Regards,</span></span></span></div><div><span class="gmail-HwtZe" lang="en"><span class="gmail-jCAhz gmail-ChMk0b"><span class="gmail-ryNqvb">Gabriel<br></span></span></span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El vie, 20 oct 2023 a la(s) 10:23, Germán Carrillo (<a href="mailto:carrillo.german@gmail.com">carrillo.german@gmail.com</a>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><i>> 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.</i><br></div><div dir="ltr"><br></div><div dir="ltr">This makes sense to me.</div><div>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.</div><div>That's why you should first create a Python variable to make it clear that the layer object should persist in the outer scope.</div><div><br></div><div>Regards,</div><div><br></div><div>Germán</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El vie, 20 oct 2023 a las 5:30, David Strip (<<a href="mailto:qgis-user@stripfamily.net" target="_blank">qgis-user@stripfamily.net</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>

  
    
  
  <div>
    <div>On 10/19/2023 10:32 AM, Gabriel De Luca
      via QGIS-Developer wrote:<br>
    </div>
    <blockquote type="cite">
      <div>Hi German,</div>
      <div><br>
      </div>
      <div>  Thanks. Yes, it works that way. Do you know why?</div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div>Regards,</div>
      <div>Gabriel</div>
    </blockquote>
    <br>
    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.<br>
  </div>

</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>-----------<br></div><div>   |\__  <br>(:>__)(<br>   |/    <br>Soluciones Geoinformáticas Libres                            <br><a href="http://geotux.tuxfamily.org/" target="_blank">http://geotux.tuxfamily.org/</a><br><a href="http://twitter.com/GeoTux2" target="_blank">https://twitter.com/GeoTux2</a></div><div><br></div><div><div><a href="http://gis.stackexchange.com/users/4972/germ%c3%a1n-carrillo" target="_blank"><img></a></div></div></div></div></div></div></div></div>
</blockquote></div>