Previously, with aContext == nullptr, the mutex would lock, but not unlock.
Then it got deadlocked inside OPENGL_GAL dtor.
(cherry picked from commit eaf65f7d53)
wxGLCanvas::IsDisplaySupported() handles wxGL_{MINOR,MAJOR}_VERSION
attributes only in 3.0.4. Since 3.1.0 the attributes are apparently not
supported, so instead wxGLContext::IsOK() is used (introduced in 3.1.0).
Fixes: lp:1775995
* https://bugs.launchpad.net/kicad/+bug/1775995
Also lock the DeleteAll call with mutext to protect threaded access.
The OpenGL contexts are removed when OPENGL_GAL class is destroyed.
Explicitly deleting all contexts prior to destroying the OPENGL_GAL
class causes an assert when the destructor tries to lock its context
prior to cleaning up OpenGL memory. In most cases, an unhandled assert
in a destructor-called function will simply exit the destructor.
Python thread cleanup will also attempt to close the context. This can
cause a race condition with multiple threads accessing/deleting the
canvas.
Fixes: lp:1774096
* https://bugs.launchpad.net/kicad/+bug/1774096