PCBnew: Adding dielectric layer causes pcbnew to crash (lp:#1853764)

[Original report](https://bugs.launchpad.net/bugs/1853764) created by **Victor W (vicw)**
```
We're using the latest git version of kicad (complete version information
follows).

When attempting to add a dielectric layer into the physical stack up,
pcbnew crashes. This is a pity because our design requires two dielectric
pre-preg layers to be beside each other.

This can be reproduced on a brand new design;

File -> Board Set Up -> Physical Stack Up

Then click on "Add Dielectric Layer". And then pcbnew segfaults.

===

Here's the backtrace:


Thread 1 "pcbnew" received signal SIGSEGV, Segmentation fault.
0x000055555cb6a7f0 in ?? ()
(gdb) bt
#0  0x000055555cb6a7f0 in  ()
#1  0x00007ffff7d0b08d in wxWindowBase::SetSizer(wxSizer*, bool) () at
/usr/lib/libwx_gtk2u_core-3.0.so.0
#2  0x00007ffff2686aa6 in
PANEL_SETUP_BOARD_STACKUP::rebuildLayerStackPanel() (this=0x555558008600)
at /usr/src/pacman/kicad-git/src/kicad-
git/pcbnew/board_stackup_manager/panel_board_stackup.cpp:765
#3  0x00007ffff2682b0e in
PANEL_SETUP_BOARD_STACKUP::onAddDielectricLayer(wxCommandEvent&)
(this=0x555558008600, event=...)
    at /usr/src/pacman/kicad-git/src/kicad-
git/pcbnew/board_stackup_manager/panel_board_stackup.cpp:195
#4  0x00007ffff77b689e in
wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&,
wxEvtHandler*, wxEvent&) () at /usr/lib/libwx_baseu-3.0.so.0
#5  0x00007ffff77b6c1b in wxEvtHandler::SearchDynamicEventTable(wxEvent&)
() at /usr/lib/libwx_baseu-3.0.so.0
#6  0x00007ffff77b6cb1 in wxEvtHandler::TryHereOnly(wxEvent&) () at
/usr/lib/libwx_baseu-3.0.so.0
#7  0x00007ffff77b6d64 in wxEvtHandler::ProcessEventLocally(wxEvent&) () at
/usr/lib/libwx_baseu-3.0.so.0
#8  0x00007ffff77b6e02 in wxEvtHandler::ProcessEvent(wxEvent&) () at
/usr/lib/libwx_baseu-3.0.so.0
#9  0x00007ffff77b6ba7 in wxEvtHandler::SafelyProcessEvent(wxEvent&) () at
/usr/lib/libwx_baseu-3.0.so.0
#10 0x00007ffff7b95a19 in  () at /usr/lib/libwx_gtk2u_core-3.0.so.0
#11 0x00007ffff6626e75 in g_closure_invoke () at
/usr/lib/libgobject-2.0.so.0
#12 0x00007ffff6613ab8 in  () at /usr/lib/libgobject-2.0.so.0
#13 0x00007ffff66181ae in g_signal_emit_valist () at
/usr/lib/libgobject-2.0.so.0
#14 0x00007ffff6619080 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
#15 0x00007ffff6b37895 in  () at /usr/lib/libgtk-x11-2.0.so.0
#16 0x00007ffff6626e75 in g_closure_invoke () at
/usr/lib/libgobject-2.0.so.0
#17 0x00007ffff6614188 in  () at /usr/lib/libgobject-2.0.so.0
#18 0x00007ffff66181ae in g_signal_emit_valist () at
/usr/lib/libgobject-2.0.so.0
#19 0x00007ffff6619080 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
#20 0x00007ffff6b367ba in  () at /usr/lib/libgtk-x11-2.0.so.0
#21 0x00007ffff6bdf7cc in  () at /usr/lib/libgtk-x11-2.0.so.0
#22 0x00007ffff6626d72 in g_closure_invoke () at
/usr/lib/libgobject-2.0.so.0
#23 0x00007ffff66137df in  () at /usr/lib/libgobject-2.0.so.0
#24 0x00007ffff661776d in g_signal_emit_valist () at
/usr/lib/libgobject-2.0.so.0
#25 0x00007ffff6619080 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
#26 0x00007ffff6cfa235 in  () at /usr/lib/libgtk-x11-2.0.so.0
#27 0x00007ffff6bdda0e in gtk_propagate_event () at
/usr/lib/libgtk-x11-2.0.so.0
#28 0x00007ffff6bdde43 in gtk_main_do_event () at
/usr/lib/libgtk-x11-2.0.so.0
#29 0x00007ffff6856d5e in  () at /usr/lib/libgdk-x11-2.0.so.0
#30 0x00007ffff65397bf in g_main_context_dispatch () at
/usr/lib/libglib-2.0.so.0
#31 0x00007ffff653b739 in  () at /usr/lib/libglib-2.0.so.0
#32 0x00007ffff653c6d2 in g_main_loop_run () at /usr/lib/libglib-2.0.so.0
#33 0x00007ffff6bdcdf3 in gtk_main () at /usr/lib/libgtk-x11-2.0.so.0
#34 0x00007ffff7b371b6 in wxGUIEventLoop::DoRun() () at
/usr/lib/libwx_gtk2u_core-3.0.so.0
#35 0x00007ffff7683bae in wxEventLoopBase::Run() () at
/usr/lib/libwx_baseu-3.0.so.0
#36 0x00007ffff7ba08f1 in wxDialog::ShowModal() () at
/usr/lib/libwx_gtk2u_core-3.0.so.0
#37 0x00007ffff2733b44 in PCB_EDIT_FRAME::DoShowBoardSetupDialog(wxString
const&, wxString const&) (this=0x5555577bfd40, aInitialPage=...,
aInitialParentPage=...)
    at /usr/src/pacman/kicad-git/src/kicad-
git/pcbnew/pcb_edit_frame.cpp:560
#38 0x00007ffff27fb5ea in PCB_EDITOR_CONTROL::BoardSetup(TOOL_EVENT const&)
(this=0x5555576ff680, aEvent=...) at /usr/src/pacman/kicad-git/src/kicad-
git/pcbnew/tools/pcb_editor_control.cpp:310
#39 0x00007ffff2805347 in std::__invoke_impl<int, int
(PCB_EDITOR_CONTROL::*&)(TOOL_EVENT const&), PCB_EDITOR_CONTROL*&,
TOOL_EVENT const&>(std::__invoke_memfun_deref, int
(PCB_EDITOR_CONTROL::*&)(TOOL_EVENT const&), PCB_EDITOR_CONTROL*&,
TOOL_EVENT const&) (__f=
   @ 0x55555aa6ba70: (int (PCB_EDITOR_CONTROL::*)(PCB_EDITOR_CONTROL *
const, const TOOL_EVENT &)) 0x7ffff27fb56a
<PCB_EDITOR_CONTROL::BoardSetup(TOOL_EVENT const&)>, __t=@0x55555aa6ba80:
0x5555576ff680, __args#0=...) at /usr/include/c++/8.3.0/bits/invoke.h:73
#40 0x00007ffff2805002 in std::__invoke<int
(PCB_EDITOR_CONTROL::*&)(TOOL_EVENT const&), PCB_EDITOR_CONTROL*&,
TOOL_EVENT const&>(int (PCB_EDITOR_CONTROL::*&)(TOOL_EVENT const&),
PCB_EDITOR_CONTROL*&, TOOL_EVENT const&) (__fn=
   @ 0x55555aa6ba70: (int (PCB_EDITOR_CONTROL::*)(PCB_EDITOR_CONTROL *
const, const TOOL_EVENT &)) 0x7ffff27fb56a
<PCB_EDITOR_CONTROL::BoardSetup(TOOL_EVENT const&)>,
__args#0=@0x55555aa6ba80: 0x5555576ff680,--Type <RET> for more, q to quit,
c to continue without paging--c
 __args#1=...) at /usr/include/c++/8.3.0/bits/invoke.h:95
#41 0x00007ffff28049f6 in std::_Bind<int
(PCB_EDITOR_CONTROL::*(PCB_EDITOR_CONTROL*,
std::_Placeholder<1>))(TOOL_EVENT const&)>::__call<int, TOOL_EVENT const&,
0ul, 1ul>(std::tuple<TOOL_EVENT const&>&&, std::_Index_tuple<0ul, 1ul>)
(this=0x55555aa6ba70, __args=...) at /usr/include/c++/8.3.0/functional:400
#42 0x00007ffff28044b6 in std::_Bind<int
(PCB_EDITOR_CONTROL::*(PCB_EDITOR_CONTROL*,
std::_Placeholder<1>))(TOOL_EVENT const&)>::operator()<TOOL_EVENT const&,
int>(TOOL_EVENT const&) (this=0x55555aa6ba70, __args#0=...) at
/usr/include/c++/8.3.0/functional:484
#43 0x00007ffff280414c in std::_Function_handler<int (TOOL_EVENT const&),
std::_Bind<int (PCB_EDITOR_CONTROL::*(PCB_EDITOR_CONTROL*,
std::_Placeholder<1>))(TOOL_EVENT const&)> >::_M_invoke(std::_Any_data
const&, TOOL_EVENT const&) (__functor=..., __args#0=...) at
/usr/include/c++/8.3.0/bits/std_function.h:282
#44 0x00007ffff2f78a09 in std::function<int (TOOL_EVENT
const&)>::operator()(TOOL_EVENT const&) const (this=0x55555aab22f0,
__args#0=...) at /usr/include/c++/8.3.0/bits/std_function.h:687


===

And here's the kicad version info:
Application: Pcbnew
Version: (5.99.0-416-gf7ded3040), debug build
Libraries:
    wxWidgets 3.0.4
    libcurl/7.64.1 OpenSSL/1.1.1b zlib/1.2.11 libidn2/2.1.1 libpsl/0.20.2
(+libidn2/2.1.1) libssh2/1.8.1 nghttp2/1.36.0
Platform: Linux 5.0.9-arch1-1-ARCH x86_64, 64 bit, Little endian, wxGTK
Build Info:
    Build date: Nov 24 2019 17:59:07
    wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
    Boost: 1.69.0
    OpenCASCADE Community Edition: 6.9.1
    Curl: 7.64.1
    Compiler: GCC 8.3.0 with C++ ABI 1013

Build settings:
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_PYTHON3=OFF
    KICAD_SCRIPTING_WXPYTHON=OFF
    KICAD_SCRIPTING_WXPYTHON_PHOENIX=OFF
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_USE_OCC=OFF
    KICAD_SPICE=ON
    KICAD_STDLIB_DEBUG=OFF
    KICAD_STDLIB_LIGHT_DEBUG=OFF
    KICAD_SANITIZE=OFF
```
Original tags: pcbnew

Story points: 6.0