← Back to team overview

kicad-developers team mailing list archive

Static initialization order fiasco

 

This week I tried to build recent revisions of KiCad. Every attempt I built them, Pcbnew fell with segmentation fault. I tried different versions of wxWidgets with different options. It did not help. It was especially strange because other developers told me that they can build and run the same revision (e.g. revision 4751) of Pcbnew normally.

As it turned out, the issue is with undefined static initialization order.

lp:kicad revision 4792 and earlier:

class_netclass.cpp (line 39):

const wxString NETCLASS::Default = wxT("Default");


class_netinfolist.cpp (line 283):

NETINFO_ITEM NETINFO_LIST::ORPHANED = NETINFO_ITEM( NULL, wxEmptyString, NETINFO_LIST::UNCONNECTED );


class_netinfo_item.cpp (line 52...):

NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName, int aNetCode ) :
    m_NetCode( aNetCode ), m_Netname( aNetName ), m_ShortNetname( m_Netname.AfterLast( '/' ) )
{
    m_parent   = aParent;
    m_RatsnestStartIdx = 0;     // Starting point of ratsnests of this net in a
                                // general buffer of ratsnest
    m_RatsnestEndIdx   = 0;     // Ending point of ratsnests of this net

    m_NetClassName = NETCLASS::Default; // !!!!! here NETCLASS::Default may not be yet initialized !!!!!
    m_NetClass = NULL;
}

If there are other known similar places in the project, please, let us know. It is difficult enough to review the whole project visually and moreover such bugs are subtle.

Alexander

Follow ups