Kicad crashes when layer chaged with zone select active (lp:#1796390)

[Original report](https://bugs.launchpad.net/bugs/1796390) created by **Connor Crenshaw (connorgames-geek)**
```
Kicad crashes after the layer is changed when the zone creation tool is
active.

To reproduce:
Create a board or load an existing board
Click on the zone creation tool
Select a board copper layer other than the currently active one using the
mouse to interact with the layers manager
Move the cursor back over the board
Kicad crashes with a failed assert

Self-built kicad e828e0d9428a8cdef0942de18056ed3314a49ea on linux mint 18
GDB log:

connor@Zoidberg:~$ gdb kicad
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from kicad...done.
(gdb) run
Starting program: /usr/local/bin/kicad
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
15:06:24: Debug: Checking template path '/usr/local/share/kicad/template'
exists
15:06:24: Debug: Checking template path '/home/connor/kicad/template'
exists
[New Thread 0x7fffe5737700 (LWP 19838)]
[New Thread 0x7fffe4f36700 (LWP 19839)]
[New Thread 0x7fffdffff700 (LWP 19840)]
03:06:24 PM: Debug: FileWatcherReset: watched paths:
03:06:24 PM: Debug:  /home/connor/Dropbox/Electronics/Blank_bugcheck/

[New Thread 0x7fffd21ff700 (LWP 19842)]
[New Thread 0x7fffd19fe700 (LWP 19843)]
[Thread 0x7fffd21ff700 (LWP 19842) exited]
[New Thread 0x7fffd21ff700 (LWP 19844)]
[Thread 0x7fffd19fe700 (LWP 19843) exited]
[New Thread 0x7fffd19fe700 (LWP 19845)]
[Thread 0x7fffd21ff700 (LWP 19844) exited]
[New Thread 0x7fffd21ff700 (LWP 19846)]
[Thread 0x7fffd19fe700 (LWP 19845) exited]
[New Thread 0x7fffd19fe700 (LWP 19847)]
[Thread 0x7fffd21ff700 (LWP 19846) exited]
[Thread 0x7fffd19fe700 (LWP 19847) exited]
[New Thread 0x7fffd21ff700 (LWP 19848)]
[New Thread 0x7fffd21ff700 (LWP 19849)]
[Thread 0x7fffd21ff700 (LWP 19848) exited]
[Thread 0x7fffd21ff700 (LWP 19849) exited]
[New Thread 0x7fffd21ff700 (LWP 19850)]
[New Thread 0x7fffd19fe700 (LWP 19851)]
[Thread 0x7fffd21ff700 (LWP 19850) exited]
[New Thread 0x7fffd21ff700 (LWP 19852)]
[Thread 0x7fffd19fe700 (LWP 19851) exited]
[New Thread 0x7fffd21ff700 (LWP 19853)]
[Thread 0x7fffd21ff700 (LWP 19852) exited]
[New Thread 0x7fffd19fe700 (LWP 19854)]
[Thread 0x7fffd21ff700 (LWP 19853) exited]
[New Thread 0x7fffd21ff700 (LWP 19855)]
[Thread 0x7fffd19fe700 (LWP 19854) exited]
[New Thread 0x7fffd21ff700 (LWP 19856)]
[Thread 0x7fffd21ff700 (LWP 19855) exited]
[Thread 0x7fffd21ff700 (LWP 19856) exited]
[New Thread 0x7fffd19fe700 (LWP 19857)]
[Thread 0x7fffd19fe700 (LWP 19857) exited]
03:06:29 PM: Debug: Loading project
'/home/connor/Dropbox/Electronics/Blank_bugcheck/Blank_bugcheck.pro'
settings.
[New Thread 0x7fffd19fe700 (LWP 19858)]
[New Thread 0x7fffd21ff700 (LWP 19859)]
[Thread 0x7fffd19fe700 (LWP 19858) exited]
[New Thread 0x7fffd19fe700 (LWP 19860)]
[Thread 0x7fffd21ff700 (LWP 19859) exited]
[New Thread 0x7fffd21ff700 (LWP 19861)]
[Thread 0x7fffd19fe700 (LWP 19860) exited]
[New Thread 0x7fffd19fe700 (LWP 19862)]
[Thread 0x7fffd21ff700 (LWP 19861) exited]
[New Thread 0x7fffd21ff700 (LWP 19863)]
[Thread 0x7fffd19fe700 (LWP 19862) exited]
[New Thread 0x7fffd19fe700 (LWP 19864)]
[Thread 0x7fffd21ff700 (LWP 19863) exited]
[New Thread 0x7fffd19fe700 (LWP 19865)]
[Thread 0x7fffd19fe700 (LWP 19864) exited]
[Thread 0x7fffd19fe700 (LWP 19865) exited]
kicad: /home/connor/kicad/include/tool/tool_event.h:250: const VECTOR2D&
TOOL_EVENT::Position() const: Assertion `m_category == TC_MOUSE' failed.

Thread 1 "kicad" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) backtrace
#0  0x00007ffff57a2e97 in __GI_raise (sig=sig@entry=6) at
../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff57a4801 in __GI_abort () at abort.c:79
#2  0x00007ffff579439a in __assert_fail_base (fmt=0x7ffff591b7d8
"%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
assertion=assertion@entry=0x7fffdee6fd9d "m_category == TC_MOUSE",
file=file@entry=0x7fffdee6fd70
"/home/connor/kicad/include/tool/tool_event.h", line=line@entry=250,
function=function@entry=0x7fffdee72460 <TOOL_EVENT::Position()
const::__PRETTY_FUNCTION__> "const VECTOR2D& TOOL_EVENT::Position() const")
at assert.c:92
#3  0x00007ffff5794412 in __GI___assert_fail (assertion=0x7fffdee6fd9d
"m_category == TC_MOUSE", file=0x7fffdee6fd70
"/home/connor/kicad/include/tool/tool_event.h", line=250,
function=0x7fffdee72460 <TOOL_EVENT::Position() const::__PRETTY_FUNCTION__>
"const VECTOR2D& TOOL_EVENT::Position() const") at assert.c:101
#4  0x00007fffde83d1a6 in TOOL_EVENT::Position() const
(this=0x5555595a5008) at /home/connor/kicad/include/tool/tool_event.h:250
#5  0x00007fffde836812 in
DRAWING_TOOL::runPolygonEventLoop(POLYGON_GEOM_MANAGER&)
(this=0x555557dd3db0, polyGeomMgr=...) at
/home/connor/kicad/pcbnew/tools/drawing_tool.cpp:1361
#6  0x00007fffde837056 in DRAWING_TOOL::drawZone(bool,
DRAWING_TOOL::ZONE_MODE) (this=0x555557dd3db0, aKeepout=false,
aMode=DRAWING_TOOL::ZONE_MODE::ADD) at
/home/connor/kicad/pcbnew/tools/drawing_tool.cpp:1493
#7  0x00007fffde832544 in DRAWING_TOOL::DrawZone(TOOL_EVENT const&)
(this=0x555557dd3db0, aEvent=...) at
/home/connor/kicad/pcbnew/tools/drawing_tool.cpp:684
#8  0x00007fffde840c91 in std::__invoke_impl<int, int
(DRAWING_TOOL::*&)(TOOL_EVENT const&), DRAWING_TOOL*&, TOOL_EVENT
const&>(std::__invoke_memfun_deref, int (DRAWING_TOOL::*&)(TOOL_EVENT
const&), DRAWING_TOOL*&, TOOL_EVENT const&) (__f=
   @ 0x555556d5af40: (int (DRAWING_TOOL::*)(DRAWING_TOOL * const, const
TOOL_EVENT &)) 0x7fffde832454 <DRAWING_TOOL::DrawZone(TOOL_EVENT const&)>,
__t=@0x555556d5af50: 0x555557dd3db0, __args#0=...) at
/usr/include/c++/7/bits/invoke.h:73
#9  0x00007fffde840aa2 in std::__invoke<int (DRAWING_TOOL::*&)(TOOL_EVENT
const&), DRAWING_TOOL*&, TOOL_EVENT const&>(int
(DRAWING_TOOL::*&)(TOOL_EVENT const&), DRAWING_TOOL*&, TOOL_EVENT const&)
(__fn=
   @ 0x555556d5af40: (int (DRAWING_TOOL::*)(DRAWING_TOOL * const, const
TOOL_EVENT &)) 0x7fffde832454 <DRAWING_TOOL::DrawZone(TOOL_EVENT const&)>,
__args#0=@0x555556d5af50: 0x555557dd3db0, __args#1=...) at
/usr/include/c++/7/bits/invoke.h:96
#10 0x00007fffde84073c in std::_Bind<int (DRAWING_TOOL::*(DRAWING_TOOL*,
std::_Placeholder<1>))(TOOL_EVENT const&)>::__call<int, TOOL_EVENT const&,
0ul, 1ul>(std::tuple<TOOL_EVENT const&>&&, std::_Index_tuple<0ul, 1ul>)
(this=0x555556d5af40, __args=...) at /usr/include/c++/7/functional:469
#11 0x00007fffde840328 in std::_Bind<int (DRAWING_TOOL::*(DRAWING_TOOL*,
std::_Placeholder<1>))(TOOL_EVENT const&)>::operator()<TOOL_EVENT const&,
int>(TOOL_EVENT const&) (this=0x555556d5af40, __args#0=...) at
/usr/include/c++/7/functional:551
#12 0x00007fffde83fb6e in std::_Function_handler<int (TOOL_EVENT const&),
std::_Bind<int (DRAWING_TOOL::*(DRAWING_TOOL*,
std::_Placeholder<1>))(TOOL_EVENT const&)> >::_M_invoke(std::_Any_data
const&, TOOL_EVENT const&) (__functor=..., __args#0=...) at
/usr/include/c++/7/bits/std_function.h:302
#13 0x00007fffdecc2079 in std::function<int (TOOL_EVENT
const&)>::operator()(TOOL_EVENT const&) const (this=0x555557f60e48,
__args#0=...) at /usr/include/c++/7/bits/std_function.h:706
#14 0x00007fffdecbee8c in COROUTINE<int, TOOL_EVENT
const&>::callerStub(long) (aData=140737488339600) at
/home/connor/kicad/include/tool/coroutine.h:329
#15 0x00007fffded26cd1 in make_fcontext () at /usr/local/bin/_pcbnew.kiface
#16 0x0000000000000000 in  ()
```

Story points: 6.0