crash when changing reference .sch in eeschema (lp:#1835841)

[Original report](https://bugs.launchpad.net/bugs/1835841) created by **Frank Severinsen (shack)**
```
Please see attached video

It's a pretty rare case, but should probably still be fixed.


Application: Eeschema
Version: 5.1.2-br-unknown-01a343f~84~ubuntu19.04.1, release build
Libraries:
    wxWidgets 3.0.4
    libcurl/7.64.0 OpenSSL/1.1.1b zlib/1.2.11 libidn2/2.0.5 libpsl/0.20.2
(+libidn2/2.0.5) libssh/0.8.6/openssl/zlib nghttp2/1.36.0 librtmp/2.3
Platform: Linux 5.0.0-20-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24
    Boost: 1.67.0
    OpenCASCADE Community Edition: 6.9.1
    Curl: 7.64.0
    Compiler: GCC 8.3.0 with C++ ABI 1013

Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=ON
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_PYTHON3=ON
    KICAD_SCRIPTING_WXPYTHON=ON
    KICAD_SCRIPTING_WXPYTHON_PHOENIX=ON
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_USE_OCC=OFF
    KICAD_SPICE=ON


Stacktrace:

Thread 1 "kicad" received signal SIGSEGV, Segmentation fault.
0x00007ffff7133de0 in __dynamic_cast () from /usr/lib/x86_64-linux-
gnu/libstdc++.so.6
(gdb) bt
#0  0x00007ffff7133de0 in __dynamic_cast () at /usr/lib/x86_64-linux-
gnu/libstdc++.so.6
#1  0x00007fffc78444d9 in  () at /usr/bin/_eeschema.kiface
#2  0x00007fffc7834a7b in  () at /usr/bin/_eeschema.kiface
#3  0x00007fffc7870136 in  () at /usr/bin/_eeschema.kiface
#4  0x00007fffc785be16 in  () at /usr/bin/_eeschema.kiface
#5  0x00007ffff74e5a8e in
wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&,
wxEvtHandler*, wxEvent&) () at /usr/lib/x86_64-linux-
gnu/libwx_baseu-3.0.so.0
#6  0x00007ffff74e5b93 in wxEventHashTable::HandleEvent(wxEvent&,
wxEvtHandler*) () at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#7  0x00007ffff74e5ecc in wxEvtHandler::TryHereOnly(wxEvent&) () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#8  0x00007fffc799d9fc in  () at /usr/bin/_eeschema.kiface
#9  0x00007ffff74e5d53 in wxEvtHandler::DoTryChain(wxEvent&) () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#10 0x00007ffff74e5ff1 in wxEvtHandler::ProcessEvent(wxEvent&) () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#11 0x00007fffc77a0241 in  () at /usr/bin/_eeschema.kiface
#12 0x00007fffc7765877 in  () at /usr/bin/_eeschema.kiface
#13 0x00007fffc77e5c6d in  () at /usr/bin/_eeschema.kiface
#14 0x00007ffff74e5a8e in
wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&,
wxEvtHandler*, wxEvent&) () at /usr/lib/x86_64-linux-
gnu/libwx_baseu-3.0.so.0
#15 0x00007ffff74e5e0a in wxEvtHandler::SearchDynamicEventTable(wxEvent&)
() at /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#16 0x00007ffff74e5ea0 in wxEvtHandler::TryHereOnly(wxEvent&) () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#17 0x00007ffff74e5f53 in wxEvtHandler::ProcessEventLocally(wxEvent&) () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#18 0x00007ffff74e5ff1 in wxEvtHandler::ProcessEvent(wxEvent&) () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#19 0x00007ffff7a83f6d in wxScrollHelperEvtHandler::ProcessEvent(wxEvent&)
() at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#20 0x00007ffff74e5d97 in wxEvtHandler::SafelyProcessEvent(wxEvent&) () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#21 0x00007ffff788f386 in wxWindow::GTKDoInsertTextFromIM(char const*) ()
at /usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#22 0x00007ffff64e5b97 in g_cclosure_marshal_VOID__STRINGv () at
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#23 0x00007ffff64e30c6 in  () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#24 0x00007ffff64ff57d in g_signal_emit_valist () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#25 0x00007ffff6500046 in g_signal_emit_by_name () at
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#26 0x00007ffff64e5b97 in g_cclosure_marshal_VOID__STRINGv () at
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#27 0x00007ffff64e30c6 in  () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#28 0x00007ffff64ff57d in g_signal_emit_valist () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#29 0x00007ffff64ffb6f in g_signal_emit () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#30 0x00007ffff04fdb33 in  () at /usr/lib/x86_64-linux-
gnu/gtk-3.0/3.0.0/immodules/im-ibus.so
#31 0x00007ffff6843833 in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#32 0x00007ffff7892aac in  () at /usr/lib/x86_64-linux-
gnu/libwx_gtk3u_core-3.0.so.0
#33 0x00007ffff69f344b in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#34 0x00007ffff64e2e8d in g_closure_invoke () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#35 0x00007ffff64f6555 in  () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#36 0x00007ffff64feb9b in g_signal_emit_valist () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#37 0x00007ffff64ffb6f in g_signal_emit () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#38 0x00007ffff69a01f4 in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#39 0x00007ffff69c149b in gtk_window_propagate_key_event () at
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#40 0x00007ffff787fc18 in  () at /usr/lib/x86_64-linux-
gnu/libwx_gtk3u_core-3.0.so.0
#41 0x00007ffff69f344b in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#42 0x00007ffff64e2e8d in g_closure_invoke () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#43 0x00007ffff64f6555 in  () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#44 0x00007ffff64feb9b in g_signal_emit_valist () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#45 0x00007ffff64ffb6f in g_signal_emit () at /usr/lib/x86_64-linux-
gnu/libgobject-2.0.so.0
#46 0x00007ffff69a01f4 in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#47 0x00007ffff6860d9f in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#48 0x00007ffff6862dfb in gtk_main_do_event () at /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0
#49 0x00007ffff65645e5 in  () at /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#50 0x00007ffff6595292 in  () at /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#51 0x00007ffff62699ee in g_main_context_dispatch () at
/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#52 0x00007ffff6269c88 in  () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#53 0x00007ffff6269f82 in g_main_loop_run () at /usr/lib/x86_64-linux-
gnu/libglib-2.0.so.0
#54 0x00007ffff6861e75 in gtk_main () at /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0
--Type <RET> for more, q to quit, c to continue without paging--
#55 0x00007ffff786dc95 in wxGUIEventLoop::DoRun() () at
/usr/lib/x86_64-linux-gnu/libwx_gtk3u_core-3.0.so.0
#56 0x00007ffff73bb76d in wxEventLoopBase::Run() () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#57 0x00007ffff73848f6 in wxAppConsoleBase::MainLoop() () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#58 0x00005555555f09d9 in  ()
#59 0x00007ffff7405fd9 in wxEntry(int&, wchar_t**) () at
/usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#60 0x00005555555d6788 in  ()
#61 0x00007ffff6d42b6b in __libc_start_main (main=0x5555555d6760, argc=1,
argv=0x7fffffffdf08, init=<optimised out>, fini=<optimised out>,
rtld_fini=<optimised out>, stack_end=0x7fffffffdef8)
    at ../csu/libc-start.c:308
#62 0x00005555555daeda in _start ()
```
Original tags: eeschema

Story points: 6.0