GerbView crashes while loading Gerber file (lp:#1796744)

[Original report](https://bugs.launchpad.net/bugs/1796744) created by **Nabeel Ahmad (nbl14)**
```
GerbView crashes while loading one particular Gerber file, which is
attached. This file has been obtained from the "PCB fabrication data -
Example 1.zip" archive on Ucamco's Gerber downloads page [1].

Hundreds of failed assertions are reported by the program. The following
detail was seen with GDB:
warning: D:/private-
local/working/kicad/kicad/gerbview/am_primitive.cpp(70): assert
"params.size() && params[0].IsImmediate()" failed in
IsAMPrimitiveExposureOn().

If all these assert messages are ignored, the program finally crashes with
the following detail:
Thread 1 received signal SIGSEGV, Segmentation fault.
0x0000000008960304 in KIGFX::VERTEX_MANAGER::ChangeItemDepth (
    this=0x248347f0, aItem=..., aDepth=129)
    at D:/private-
local/working/kicad/kicad/common/gal/opengl/vertex_manager.cpp:204
204             vertex->z = aDepth;

A backtrace of the crash has been obtained using GDB and is copied below at
[2].

------------------------------------------------------------------------------------

[1] https://www.ucamco.com/en/file-formats/gerber/downloads

[2] Backtrace:
#0  0x0000000008960304 in KIGFX::VERTEX_MANAGER::ChangeItemDepth (
    this=0x248347f0, aItem=..., aDepth=129)
    at D:/private-
local/working/kicad/kicad/common/gal/opengl/vertex_manager.cpp:204
#1  0x000000000895b33d in KIGFX::OPENGL_GAL::ChangeGroupDepth (
    this=0x248d20f0, aGroupNumber=0, aDepth=129)
    at D:/private-
local/working/kicad/kicad/common/gal/opengl/opengl_gal.cpp:1455
#2  0x00000000088dc78c in KIGFX::VIEW::UpdateAllLayersOrder
(this=0x247624c0)
    at D:/private-local/working/kicad/kicad/common/view/view.cpp:929
#3  0x00000000088680c3 in GERBVIEW_DRAW_PANEL_GAL::SetTopLayer (
    this=0x22f39b20, aLayer=163)
    at D:/private-
local/working/kicad/kicad/gerbview/gerbview_draw_panel_gal.cpp:175
#4  0x0000000008867c02 in GERBVIEW_DRAW_PANEL_GAL::SetHighContrastLayer (
    this=0x22f39b20, aLayer=163)
    at D:/private-
local/working/kicad/kicad/gerbview/gerbview_draw_panel_gal.cpp:82
#5  0x000000000884a93a in GERBVIEW_FRAME::SetActiveLayer (this=0x22f2dac0,
    aLayer=1, doLayerWidgetUpdate=true)
    at D:/private-local/working/kicad/kicad/gerbview/gerbview_frame.cpp:949
#6  0x000000000884295f in GERBVIEW_FRAME::loadListOfGerberFiles (
    this=0x22f2dac0, aPath=..., aFilenameList=...)
    at D:/private-local/working/kicad/kicad/gerbview/files.cpp:323
#7  0x0000000008841ddb in GERBVIEW_FRAME::LoadGerberFiles (this=0x22f2dac0,
    aFullFileName=...)
    at D:/private-local/working/kicad/kicad/gerbview/files.cpp:222
#8  0x0000000008840bc5 in GERBVIEW_FRAME::OnGbrFileHistory
(this=0x22f2dac0,
    event=...) at D:/private-
local/working/kicad/kicad/gerbview/files.cpp:61
#9  0x000000006a4c2f24 in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#10 0x000000006a62cd42 in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#11 0x000000006a62ce48 in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#12 0x000000006a62d254 in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#13 0x00000000088b29f9 in EDA_BASE_FRAME::ProcessEvent (this=0x22f2dac0,
    aEvent=...)
    at D:/private-local/working/kicad/kicad/common/eda_base_frame.cpp:173
#14 0x000000006a62d003 in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#15 0x000000006a62d321 in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#16 0x00000000064b449f in ?? ()
   from C:\msys64\mingw64\bin\wxmsw30u_core_gcc_custom.dll
#17 0x000000006a62d05b in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#18 0x0000000006461f8d in ?? ()
   from C:\msys64\mingw64\bin\wxmsw30u_core_gcc_custom.dll
#19 0x00000000062fea70 in ?? ()
   from C:\msys64\mingw64\bin\wxmsw30u_core_gcc_custom.dll
#20 0x00007ffc4f44b85d in USER32!CallWindowProcW ()
   from C:\Windows\System32\user32.dll
#21 0x00007ffc4f44b1ef in USER32!DispatchMessageW ()
   from C:\Windows\System32\user32.dll
#22 0x00000000062f5e8b in ?? ()
   from C:\msys64\mingw64\bin\wxmsw30u_core_gcc_custom.dll
#23 0x000000006a4fc6d0 in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#24 0x000000006a4fc339 in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#25 0x000000006a4c68fa in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#26 0x0000000000435a82 in APP_SINGLE_TOP::OnRun (this=0x6862850)
    at D:/private-local/working/kicad/kicad/common/single_top.cpp:186
#27 0x000000006a547977 in ?? ()
   from C:\msys64\mingw64\bin\wxbase30u_gcc_custom.dll
#28 0x00000000061ca24b in ?? ()
   from C:\msys64\mingw64\bin\wxmsw30u_core_gcc_custom.dll
#29 0x00000000004016ec in WinMain (hInstance=0x400000, hPrevInstance=0x0,
    nCmdShow=10)
    at D:/private-local/working/kicad/kicad/common/single_top.cpp:260
#30 0x000000000045c502 in main (flags=<optimized out>,
    cmdline=<optimized out>, inst=<optimized out>)
    at C:/repo/mingw-w64-crt-
git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18
#31 0x00000000004013a5 in __tmainCRTStartup ()
    at C:/repo/mingw-w64-crt-
git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:339
#32 0x00000000004014db in WinMainCRTStartup ()
    at C:/repo/mingw-w64-crt-
git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:195

[3] Version information:
Application: gerbview
Version: (6.0.0-rc1-dev-713-g90df7a8b2), debug build
Libraries:
    wxWidgets 3.0.4
    libcurl/7.61.1 OpenSSL/1.1.1 (WinSSL) zlib/1.2.11 brotli/1.0.6
libidn2/2.0.5 libpsl/0.20.2 (+libidn2/2.0.5) nghttp2/1.33.0
Platform: Windows 8 (build 9200), 64-bit edition, 64 bit, Little endian,
wxMSW
Build Info:
    wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8)
    Boost: 1.68.0
    OpenCASCADE Community Edition: 6.9.1
    Curl: 7.61.1
    Compiler: GCC 8.2.0 with C++ ABI 1013

Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_WXPYTHON=ON
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_USE_OCC=OFF
    KICAD_SPICE=ON
```
Original tags: gerbview

Story points: 6.0