Fixed a crash on shutdown