added code to check if window has been closed (via glError() function) and then exit the process