← Back to team overview

kicad-developers team mailing list archive

Re: Help needed

 


Le 25/09/2020 à 16:32, Jon Evans a écrit :
Can you run with ASAN on (KICAD_SANITIZE in CMake) and see if you get some info about why you get a segfault?

On Fri, Sep 25, 2020 at 10:28 AM Franck Jullien <franck.jullien@xxxxxxxxx <mailto:franck.jullien@xxxxxxxxx>> wrote:

    Hi,

    I'm working on the intersheets references functionality and I'm
    struggling with a segfault.
    Until now, I didn't try to remove iref from sheets. Now, I do this
    with:

    void SCH_EDIT_FRAME::RemoveAllIntersheetsRefs()
    {
        SCH_SHEET_LIST sheets = Schematic().GetSheets();
        SCH_GLOBALLABEL* gLabel;

        m_labelTable.clear();

        for( const SCH_SHEET_PATH& sheet : sheets )
        {
            SCH_SCREEN* screen = sheet.LastScreen();

            for( SCH_ITEM* item : screen->Items() )
            {

                if( item->Type() == SCH_GLOBAL_LABEL_T )
                {
                    gLabel = (SCH_GLOBALLABEL*)( item );
                    SCH_IREF* iref = gLabel->GetIref();

                    if( iref )
                    {
                        gLabel->SetIref( nullptr );
                        gLabel->SetIrefSavedPosition( wxDefaultPosition );
                        screen->DeleteItem( iref );
                    }
                }
            }
        }
    }

    As soon as I call DeleteItem (or RemoveFromScreen) I get a crash.
    Is there something obvious I don't see ?

    I still need to get familiar with screens, sheets, frames, canvas,
    views....

    Thanks in advance.

    Franck.


I am guessing screen->DeleteItem( iref ); remove an item from screen->Items()

Usually, when removing an item from a list, the pointers used to explore the list become invalid.

But screen->Items() is a rtree, and I am not experienced with rtrees.

I am unsure exploring all sheets is working well in complex hierarchies (complex hierarchies are hierarchies with a sheet instantiated more than once.

Probably exploring the screen list is enough.


--
Jean-Pierre CHARRAS


References