Fixed range check error when switching windows.