Segmentation Fault when referencing a fault


Getting segmentation fault when trying to assign a font.

What MCU/Processor/Board and compiler are you using?

Raspberry Pi

What do you want to achieve?

Would be nice if it did not crash !

What have you tried so far?


Code to reproduce

I currently have defined three fonts which are used to render different parts of my screen.
Note that this code is C++ and the variables are private members of my screen class and the fonts are assigned in the class constructor.

The font member variables are defined as such:

        const lv_font_t		* _smallFont;
        const lv_font_t		* _normalFont;
        const lv_font_t		* _largeFont;

I assign them thus:

    _smallFont = &lv_font_montserrat_12;
    _normalFont = &lv_font_montserrat_16;
    _largeFont = &lv_font_montserrat_28;

This all seems to work fine.
Then I decided I needed another font so I added:

        const lv_font_t		* _readoutFont;


    _readoutFont = &lv_font_montserrat_24;

When I run this code I immediately get a Segmentation fault.
If I comment out _readoutFont = &lv_font_montserrat_24; then the code runs fine !

Screenshot and/or video


Any thoughts what I might be doing wrong ?


It seems likely that this change is revealing an existing issue somewhere within your codebase. I can’t see why adding another variable would cause a crash in and of itself. Have you tried using GDB to find where the segfault occurs?

Yes I was using gdb to try to get to the bottom of the issue. Without debug symbols it was saying that the fault was in lv_get_style (or something like that). I enabled debug symbols to get a better handle on where the issue is but now the code works without faulting :frowning:


How are you enabling debug symbols? You may inadvertently be adjusting the optimization level at the same time (that option starts with -O) which will change the program’s behavior.

I have not changed the optimisations from level 3 (-O3), I have simply added the -g switch to the compiler.