[prev in list] [next in list] [prev in thread] [next in thread] 

List:       qgis-developer
Subject:    Re: [QGIS-Developer] segmentation fault in standalone script using PyQGIS
From:       Mélanie_Dol_via_QGIS-Developer <qgis-developer () lists ! osgeo ! org>
Date:       2022-10-31 16:26:49
Message-ID: 9e0b7e55-aea4-ac4f-9aa6-f0ae538aa65b () sat-ocean ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Jacky,

Thank you so much, the segmentation fault has disappeared.

However, my styles don't work. I guess my script can't access to my 
symbols pre-configured. Is there a path to add or anything else ?

Another question, how to force a label placement mode to "horizontal" ?

Many thanks and regards,

Mélanie

On 10/31/22 12:14 PM, Jacky Volpes via QGIS-Developer wrote:
> Hi Mélanie,
> 
> Thanks for the script, I was able to reproduce the segmentation fault 
> with a dummy gpkg I made.
> 
> After some investigations, it seems that the symbol named 
> "style_layer" used in
> 1. the addSymbol() method for the first layer
> 2. & 3. the QgsRendererCategory() constructor for the second and 
> third layer
> is None (nullptr -> hence  the segfault).
> 
> If I add the following
> 
> if style_layer is None:
> style_layer = 
> QgsSymbol.defaultSymbol(Layer_Pressure_Center.geometryType())
> 
> just before using style_layer as a safe check (for each layer of 
> course) everything works fine.
> Maybe it's simply because I don't have these symbols pre-configured, 
> but it's worth the check on your side.
> 
> Also, I encapsulated the code like this, which prevents another 
> segfault to occur due to local/global scope stuff I think:
> 
> ---
> 
> all imports
> 
> def main():
> the main code
> 
> if__name__ == '__main__':
> set prefix path
> create qgs application
> append plugins path to sys.path and import processing stuff
> main()
> qgs.exitQgis()
> 
> ---
> 
> 
> Regards,
> Jacky
> 
> 
> 
> Le 28/10/2022 à 17:10, Mélanie Dol via QGIS-Developer a écrit :
> > Hi Jacky,
> > 
> > Yes of course. Please find attached my script.
> > 
> > Regards,
> > 
> > Mélanie
> > 
> > On 10/28/22 4:55 PM, Jacky Volpes via QGIS-Developer wrote:
> > > Hi Mélanie,
> > > 
> > > Have you initialized your standalone script as shown in 
> > > https://docs.qgis.org/3.22/en/docs/pyqgis_developer_cookbook/intro.html#using-pyqgis-in-standalone-scripts \
> > >  ?
> > > 
> > > Best regards,
> > > Jacky
> > > 
> > > 
> > > Le 28/10/2022 à 16:40, Mélanie Dol via QGIS-Developer a écrit :
> > > > Hi Andrea,
> > > > 
> > > > Thank you. I've updated with QGIS 3.26 Buenos Aires. The warning 
> > > > message have disappeared. Unfortunately, the script still generates 
> > > > a segmentation fault.
> > > > 
> > > > Best regards,
> > > > 
> > > > Mélanie Dol
> > > > 
> > > > On 10/28/22 11:47 AM, Andrea Giudiceandrea via QGIS-Developer wrote:
> > > > > Il 27/10/2022 16:34, Mélanie Dol via QGIS-Developer ha scritto:
> > > > > > /usr/share/qgis/python/plugins/processing/algs/grass7/Grass7Utils.py:191: \
> > > > > >                 
> > > > > > SyntaxWarning: "is" with a literal. Did you mean "=="?
> > > > > > if path is '':
> > > > > 
> > > > > Hi Mélanie,
> > > > > while I don't know why that script generates a segmentation fault, 
> > > > > It seems you are using QGIS 3.10 which is a three years old 
> > > > > version. The QGIS repository for Ubuntu 20.04 currently offers the 
> > > > > latest available QGIS LTR 3.22.12.
> > > > > 
> > > > > Best regards.
> > > > > 
> > > > > Andrea Giudiceandrea
> > > > > 
> > > > > _______________________________________________
> > > > > QGIS-Developer mailing list
> > > > > QGIS-Developer@lists.osgeo.org
> > > > > List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > > > > Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > > > 
> > > > 
> > > > _______________________________________________
> > > > QGIS-Developer mailing list
> > > > QGIS-Developer@lists.osgeo.org
> > > > List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > > > Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > > 
> > > -- 
> > > Jacky Volpes
> > > 
> > > Ingénieur SIG - Oslandia
> > > 
> > > _______________________________________________
> > > QGIS-Developer mailing list
> > > QGIS-Developer@lists.osgeo.org
> > > List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > > Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > 
> > 
> > _______________________________________________
> > QGIS-Developer mailing list
> > QGIS-Developer@lists.osgeo.org
> > List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
> -- 
> Jacky Volpes
> 
> Ingénieur SIG - Oslandia
> 
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[Attachment #5 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Hi Jacky,<br>
    <br>
    Thank you so much, the segmentation fault has disappeared. <br>
    <br>
    However, my styles don't work. I guess my script can't access to my
    symbols pre-configured. Is there a path to add or anything else ?<br>
    <br>
    Another question, how to force a label placement mode to
    "horizontal" ?<br>
    <br>
    Many thanks and regards,<br>
    <br>
    Mélanie<br>
    <br>
    <div class="moz-cite-prefix">On 10/31/22 12:14 PM, Jacky Volpes via
      QGIS-Developer wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:abc2b597-2892-6908-b7ef-875528cc36f6@oslandia.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <font face="Ubuntu">Hi Mélanie,<br>
        <br>
        Thanks for the script, I was able to reproduce the segmentation
        fault with a dummy gpkg I made.<br>
        <br>
        After some investigations, it seems that the symbol named
        "style_layer" used in<br>
            1. the addSymbol() method for the first layer<br>
            2. &amp; 3. the QgsRendererCategory() constructor for the
        second and third layer<br>
        is None (nullptr -&gt; hence  the segfault).<br>
        <br>
        If I add the following<br>
        <br>
      </font><font face="Ubuntu">     if style_layer is None:<br>
                style_layer =
        QgsSymbol.defaultSymbol(Layer_Pressure_Center.geometryType())<br>
        <br>
        just before using style_layer as a safe check (for each layer of
        course) everything works fine.<br>
        Maybe it's simply because I don't have these symbols
        pre-configured, but it's worth the check on your side.<br>
        <br>
        Also, I encapsulated the code like this, which prevents another 
        segfault to occur due to local/global scope stuff I think:<br>
        <br>
        ---<br>
        <br>
        all imports<br>
        <br>
        def main():<br>
            the main code<br>
        <br>
        if__name__ == '__main__':<br>
            set prefix path<br>
            create qgs application<br>
            append plugins path to sys.path and import processing stuff<br>
            main()<br>
            qgs.exitQgis()<br>
        <br>
        ---<br>
        <br>
        <br>
        Regards,<br>
        Jacky<br>
        <br>
        <br>
        <br>
      </font>
      <div class="moz-cite-prefix">Le 28/10/2022 à 17:10, Mélanie Dol
        via QGIS-Developer a écrit :<br>
      </div>
      <blockquote type="cite"
        cite="mid:3e64046b-dddc-4c81-4eca-2274110ee959@sat-ocean.com">
        <meta http-equiv="Content-Type" content="text/html;
          charset=UTF-8">
        Hi Jacky,<br>
        <br>
        Yes of course. Please find attached my script.<br>
        <br>
        Regards,<br>
        <br>
        Mélanie<br>
        <br>
        <div class="moz-cite-prefix">On 10/28/22 4:55 PM, Jacky Volpes
          via QGIS-Developer wrote:<br>
        </div>
        <blockquote type="cite"
          cite="mid:a384c6a6-231f-818e-c372-9184d116fed2@oslandia.com">
          <meta http-equiv="Content-Type" content="text/html;
            charset=UTF-8">
          <font face="Ubuntu">Hi Mélanie,<br>
            <br>
            Have you initialized your standalone script as shown in <a
              class="moz-txt-link-freetext"
href="https://docs.qgis.org/3.22/en/docs/pyqgis_developer_cookbook/intro.html#using-pyqgis-in-standalone-scripts"
                
              moz-do-not-send="true">https://docs.qgis.org/3.22/en/docs/pyqgis_developer_cookbook/intro.html#using-pyqgis-in-standalone-scripts</a>
  ?<br>
            <br>
            Best regards,<br>
            Jacky<br>
            <br>
          </font><br>
          <div class="moz-cite-prefix">Le 28/10/2022 à 16:40, Mélanie
            Dol via QGIS-Developer a écrit :<br>
          </div>
          <blockquote type="cite"
            cite="mid:742f80e5-e96e-245f-c1d4-93fe694b7c37@sat-ocean.com">
            <meta http-equiv="Content-Type" content="text/html;
              charset=UTF-8">
            Hi Andrea,<br>
            <br>
            Thank you. I've updated with QGIS 3.26 Buenos Aires. The
            warning message have disappeared. Unfortunately, the script
            still generates a segmentation fault.<br>
            <br>
            Best regards,<br>
            <br>
            Mélanie Dol<br>
            <br>
            <div class="moz-cite-prefix">On 10/28/22 11:47 AM, Andrea
              Giudiceandrea via QGIS-Developer wrote:<br>
            </div>
            <blockquote type="cite"
              cite="mid:bec35ce9-a7eb-0757-3b15-1431307d5053@libero.it">
              <meta http-equiv="Content-Type" content="text/html;
                charset=UTF-8">
              Il 27/10/2022 16:34, Mélanie Dol via QGIS-Developer ha
              scritto:<br>
              <blockquote type="cite"
                cite="mid:a7be7c28-51d0-d7e9-d55f-a8f2be904089@sat-ocean.com">
                <meta http-equiv="content-type" content="text/html;
                  charset=UTF-8">
                <font \
color="#e11111">/usr/share/qgis/python/plugins/processing/algs/grass7/Grass7Utils.py:191:
                
                  SyntaxWarning: "is" with a literal. Did you mean "=="?<br>
                    if path is '':</font><br>
              </blockquote>
              <br>
              Hi Mélanie,<br>
              while I don't know why that script generates a
              segmentation fault, It seems you are using QGIS 3.10 which
              is a three years old version. The QGIS repository for
              Ubuntu 20.04 currently offers the latest available QGIS
              LTR 3.22.12.<br>
              <br>
              Best regards.<br>
              <br>
              Andrea Giudiceandrea<br>
              <br>
              <fieldset class="mimeAttachmentHeader"></fieldset>
              <pre class="moz-quote-pre" \
wrap="">_______________________________________________ QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated moz-txt-link-freetext" \
href="mailto:QGIS-Developer@lists.osgeo.org" \
moz-do-not-send="true">QGIS-Developer@lists.osgeo.org</a> List info: <a \
class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" \
                moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
                
Unsubscribe: <a class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" \
moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a> \
</pre>  </blockquote>
            <br>
            <br>
            <fieldset class="moz-mime-attachment-header"></fieldset>
            <pre class="moz-quote-pre" \
wrap="">_______________________________________________ QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated moz-txt-link-freetext" \
href="mailto:QGIS-Developer@lists.osgeo.org" \
moz-do-not-send="true">QGIS-Developer@lists.osgeo.org</a> List info: <a \
class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" \
                moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
                
Unsubscribe: <a class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" \
moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a> \
</pre>  </blockquote>
          <br>
          <pre class="moz-signature" cols="72">-- 
Jacky Volpes

Ingénieur SIG - Oslandia</pre>
          <br>
          <fieldset class="mimeAttachmentHeader"></fieldset>
          <pre class="moz-quote-pre" \
wrap="">_______________________________________________ QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated moz-txt-link-freetext" \
href="mailto:QGIS-Developer@lists.osgeo.org" \
moz-do-not-send="true">QGIS-Developer@lists.osgeo.org</a> List info: <a \
class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" \
                moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
                
Unsubscribe: <a class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" \
moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a> \
</pre>  </blockquote>
        <br>
        <br>
        <fieldset class="moz-mime-attachment-header"></fieldset>
        <pre class="moz-quote-pre" \
wrap="">_______________________________________________ QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:QGIS-Developer@lists.osgeo.org" \
moz-do-not-send="true">QGIS-Developer@lists.osgeo.org</a> List info: <a \
class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" \
                moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
                
Unsubscribe: <a class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" \
moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a> \
</pre>  </blockquote>
      <br>
      <pre class="moz-signature" cols="72">-- 
Jacky Volpes

Ingénieur SIG - Oslandia</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" \
wrap="">_______________________________________________ QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated" \
href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a> List \
info: <a class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
                
Unsubscribe: <a class="moz-txt-link-freetext" \
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
 </pre>
    </blockquote>
    <br>
  </body>
</html>



_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic