[QGIS-Developer] segmentation fault in standalone script using PyQGIS

Jacky Volpes jacky.volpes at oslandia.com
Mon Oct 31 04:14:42 PDT 2022


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 at 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 at 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 at 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 at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20221031/18a9c288/attachment-0001.htm>


More information about the QGIS-Developer mailing list