Changed to use thread_local.
Fixed the assertion error when instantiating windows.