Made emulator exit if window is closed during waitkey loop