fixed crash bug when running in headless mode