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

Mélanie Dol Melanie.Dol at sat-ocean.com
Mon Oct 31 09:26:49 PDT 2022


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 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
>
> _______________________________________________
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20221031/0c25028c/attachment.htm>


More information about the QGIS-Developer mailing list