Crash on opening eeschema with no default libraries (namely power) installed

Bug #1728648 reported by Thomas Figueroa
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
KiCad
Fix Released
High
Wayne Stambaugh

Bug Description

Application: kicad
Version: (2017-10-29 revision b545049dc)-master, release build
Libraries:
    wxWidgets 3.1.1
    libcurl/7.55.1-DEV OpenSSL/1.0.2l zlib/1.2.11 libssh2/1.8.0
Platform: Windows 10 (build 17025), 64-bit edition, 64 bit, Little endian, wxMSW
Build Info:
    wxWidgets: 3.1.1 (wchar_t,wx containers)
    Boost: 1.65.1
    Curl: 7.55.1-DEV
    Compiler: Visual C++ 1911 without C++ ABI
Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=OFF
    KICAD_SCRIPTING_MODULES=OFF
    KICAD_SCRIPTING_WXPYTHON=OFF
    KICAD_SCRIPTING_ACTION_MENU=OFF
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_SPICE=OFF

I don't install the default libraries and what happens is if KiCad can't find my libraries, it will crash, because it forces a load of the "power" library that doesn't exist.
Seen here beginning at class_library.cpp Line 553 for context:

void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress )
{
    wxString filename;
    wxString libs_not_found;
    SEARCH_STACK* lib_search = aProject->SchSearchS();

#if defined(DEBUG) && 0
    lib_search->Show( __func__ );
#endif

    wxArrayString lib_names;

    LibNamesAndPaths( aProject, false, NULL, &lib_names );

    // If the list is empty, force loading the standard power symbol library.
    if( !lib_names.GetCount() )
        lib_names.Add( "power" );

    wxASSERT( !size() ); // expect to load into "this" empty container.

    wxProgressDialog lib_dialog( _( "Loading Symbol Libraries" ),
                                 wxEmptyString,
                                 lib_names.GetCount(),
                                 NULL,
                                 wxPD_APP_MODAL );

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

I'm not getting a crash when no libraries are defined and power library is missing. Just a dialog warning that the power.lib cannot be found. Is is possible that something else is causing the crash?

Changed in kicad:
status: New → Incomplete
Revision history for this message
Thomas Figueroa (tom-figueroa) wrote :

Indeed, that wasn't causing the crash. I noticed that I wasn't getting a crash when using a heap profiler, so I assumed it was something to do with timing.
I added wxMilliSleep(50) on Line 640 before:

if( aShowProgress )
{
    lib_dialog.Destroy();
}

and voila, no heap corruption, no crash. I don't have much knowledge of wxwidgets, but I'm assuming it destroys the dialog before the lib_dialog is finished updating the progress dialog.

Revision history for this message
Wayne Stambaugh (stambaughw) wrote : Re: [Bug 1728648] Re: Crash on opening eeschema with no default libraries (namely power) installed

Try commenting out:

if( aShowProgress )
{
    lib_dialog.Destroy();
}

from the code and see if that fixes the issue. I don't think we should
be calling Destroy() for a dialog created on the stack. IFAIR,
Destroy() deletes the window object from the heap. I doubt calling
delete on a stack pointer is a good idea. The reason the delay may have
helped is that Destroy() does not destroy the window immediately. It
places the window in a queue to be destroyed at idle time. What
concerns me is why we never saw this issue before.

On 10/30/2017 9:42 PM, Thomas Figueroa wrote:
> Indeed, that wasn't causing the crash. I noticed that I wasn't getting a crash when using a heap profiler, so I assumed it was something to do with timing.
> I added wxMilliSleep(50) on Line 640 before:
>
> if( aShowProgress )
> {
> lib_dialog.Destroy();
> }
>
> and voila, no heap corruption, no crash. I don't have much knowledge of
> wxwidgets, but I'm assuming it destroys the dialog before the lib_dialog
> is finished updating the progress dialog.
>

Revision history for this message
Thomas Figueroa (tom-figueroa) wrote :

Yup, it worked, and your hypothesis sounds reasonable. Thank you for looking into this.

Changed in kicad:
importance: Undecided → High
status: Incomplete → Confirmed
assignee: nobody → Wayne Stambaugh (stambaughw)
Changed in kicad:
status: Confirmed → Fix Committed
Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

I noticed you are using wx 3.1.1. I'm wondering if there is a change in 3.1 that is causing the issue. None the less, calling Destroy() is incorrect so committed the fix for this. Please let me know if you find any issues with the fix.

Revision history for this message
KiCad Janitor (kicad-janitor) wrote :

Fixed in revision 83cf726cd611e421af9d590768f8af8f55d52791
https://git.launchpad.net/kicad/patch/?id=83cf726cd611e421af9d590768f8af8f55d52791

Changed in kicad:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.