Fixed a layer shutdown problem in non-main layer threads.