Fixed a bug where the game would crash after change of window focus