Adds window-open check so program closes smoothly

Without check, the opengl context would not exit and the program would have to be forcibly shut down ("kill -9" style)