changed exit(0) to exit(EXIT_FAILURE) for OpenGLWindow functions, and changed printf to fprintf(stderr for error string printing.

This commit is contained in:
Jonathan Tompson 2017-08-24 15:18:43 -07:00
parent a119a77bc7
commit 29acd99d25
3 changed files with 49 additions and 44 deletions

View File

@ -135,16 +135,20 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) {
m_data->success = eglBindAPI(EGL_OPENGL_API);
if (!m_data->success) {
printf("Failed to bind OpenGL API.\n");
exit(0);
// TODO: Properly handle this error (requires change to default window
// API to change return on all window types to bool).
fprintf(stderr, "Failed to bind OpenGL API.\n");
exit(EXIT_FAILURE);
}
m_data->success =
eglChooseConfig(m_data->egl_display, egl_config_attribs,
&m_data->egl_config, 1, &m_data->num_configs);
if (!m_data->success) {
printf("Failed to choose a valid an EGLConfig.\n");
exit(0);
// TODO: Properly handle this error (requires change to default window
// API to change return on all window types to bool).
fprintf(stderr, "Failed to bind OpenGL API.\n");
exit(EXIT_FAILURE);
}
m_data->egl_surface = eglCreatePbufferSurface(

View File

@ -62,7 +62,7 @@ GLuint gltLoadShaderPair(const char *szVertexProg, const char *szFragmentProg)
glGetShaderInfoLog( hFragmentShader, 256, NULL, temp);
fprintf( stderr, "Compile failed:\n%s\n", temp);
assert(0);
exit(0);
exit(EXIT_FAILURE);
glDeleteShader(hVertexShader);
glDeleteShader(hFragmentShader);
return (GLuint)NULL;

View File

@ -222,61 +222,62 @@ struct InternalData2
m_x11_library = dlopen(X11_LIBRARY, RTLD_LOCAL | RTLD_NOW);
if (!m_x11_library)
{
printf("Error opening X11 library %s\n", X11_LIBRARY);
exit(0);
// TODO: Properly handle this error.
fprintf(stderr, "Error opening X11 library %s\n", X11_LIBRARY);
exit(EXIT_FAILURE);
}
bool missingFunc = false;
missingFunc = ((m_x11_XFree = (PFNXFREE) dlsym(m_x11_library, "XFree"))==NULL) | missingFunc;
assert(!missingFunc);
if (missingFunc) { printf("Error: missing func XFree in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XFree in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XSetErrorHandler = (PFNXSETERRORHANDLER) dlsym(m_x11_library,"XSetErrorHandler"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XSetErrorHandler in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XSetErrorHandler in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XSetErrorHandler = (PFNXSETERRORHANDLER) dlsym(m_x11_library,"XSetErrorHandler"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XSetErrorHandler in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XSetErrorHandler in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XSync = (PFNXSYNC) dlsym(m_x11_library,"XSync"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XSync in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XSync in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XOpenDisplay = (PFNXOPENDISPLAY) dlsym(m_x11_library,"XOpenDisplay"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XOpenDisplay in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XOpenDisplay in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XCreateColormap = (PFNXCREATECOLORMAP) dlsym(m_x11_library,"XCreateColormap"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XCreateColormap in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XCreateColormap in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XCreateWindow = (PFNXCREATEWINDOW) dlsym(m_x11_library,"XCreateWindow"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XCreateWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XCreateWindow in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XMapWindow = (PFNXMAPWINDOW) dlsym(m_x11_library,"XMapWindow"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XMapWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XMapWindow in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XStoreName = (PFNXSTORENAME) dlsym(m_x11_library,"XStoreName"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XStoreName in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XStoreName in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XCloseDisplay = (PFNXCLOSEDISPLAY) dlsym(m_x11_library,"XCloseDisplay"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XCloseDisplay in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XCloseDisplay in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XDestroyWindow = (PFNXDESTROYWINDOW) dlsym(m_x11_library,"XDestroyWindow"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XDestroyWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XDestroyWindow in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XRaiseWindow = (PFNXRAISEWINDOW) dlsym(m_x11_library,"XRaiseWindow"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XRaiseWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XRaiseWindow in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XGetKeyboardMapping = (PFNXGETKEYBOARDMAPPING) dlsym(m_x11_library,"XGetKeyboardMapping"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XGetKeyboardMapping in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XGetKeyboardMapping in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XKeycodeToKeysym = (PFNXKEYCODETOKEYSYM) dlsym(m_x11_library,"XKeycodeToKeysym"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XKeycodeToKeysym in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XKeycodeToKeysym in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XConvertCase = (PFNXCONVERTCASE) dlsym(m_x11_library,"XConvertCase"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XConvertCase in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XConvertCase in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XPending = (PFNXPENDING) dlsym(m_x11_library,"XPending"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XPending in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XPending in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XNextEvent = (PFNXNEXTEVENT) dlsym(m_x11_library,"XNextEvent"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XNextEvent in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XNextEvent in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XEventsQueued = (PFNXEVENTSQUEUED) dlsym(m_x11_library,"XEventsQueued"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XEventsQueued in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XEventsQueued in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XPeekEvent = (PFNXPEEKEVENT) dlsym(m_x11_library,"XPeekEvent"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XPeekEvent in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XPeekEvent in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XLookupKeysym = (PFNXLOOKUPKEYSYM) dlsym(m_x11_library,"XLookupKeysym"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XLookupKeysym in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XLookupKeysym in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
missingFunc = ((m_x11_XGetWindowAttributes = (PFNXGETWINDOWATTRIBUTES) dlsym(m_x11_library,"XGetWindowAttributes"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XGetWindowAttributes in %s, exiting!\n", X11_LIBRARY); exit(0);}
if (missingFunc) { fprintf(stderr, "Error: missing func XGetWindowAttributes in %s, exiting!\n", X11_LIBRARY); exit(EXIT_FAILURE);}
if (missingFunc)
{
printf("Error: a missing func in %s, exiting!\n", X11_LIBRARY);
exit(0);
fprintf(stderr, "Error: a missing func in %s, exiting!\n", X11_LIBRARY);
exit(EXIT_FAILURE);
} else
{
printf("X11 functions dynamically loaded using dlopen/dlsym OK!\n");
@ -445,7 +446,7 @@ void X11OpenGLWindow::enableOpenGL()
if ( ctxErrorOccurred || !ctx )
{
printf( "Failed to create an OpenGL context\n" );
fprintf(stderr, "Failed to create an OpenGL context\n" );
exit(1);
}
@ -477,8 +478,8 @@ void X11OpenGLWindow::enableOpenGL()
printf("glewOpenGL11Init OK!\n");
} else
{
printf("ERROR: glewOpenGL11Init failed, exiting!\n");
exit(0);
fprintf(stderr, "ERROR: glewOpenGL11Init failed, exiting!\n");
exit(EXIT_FAILURE);
}
}
@ -520,8 +521,8 @@ void X11OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
m_data->m_glHeight = ci.m_height;
if(m_data->m_dpy == NULL) {
printf("\n\tcannot connect to X server\n\n");
exit(0);
fprintf(stderr, "\n\tcannot connect to X server\n\n");
exit(EXIT_FAILURE);
}
m_data->m_root = DefaultRootWindow(m_data->m_dpy);
@ -534,8 +535,8 @@ if (res==0)
printf("glewXInit OK\n");
} else
{
printf("glewXInit failed, exit\n");
exit(0);
fprintf(stderr, "glewXInit failed, exit\n");
exit(EXIT_FAILURE);
}
#endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
@ -550,8 +551,8 @@ if (res==0)
int glxMinor, glxMajor;
if (!glXQueryVersion(m_data->m_dpy,&glxMajor,&glxMinor) || (((glxMajor==1)&&(glxMinor<3)) || (glxMajor<1)))
{
printf("Invalid GLX version: major %d, minor %d\n",glxMajor,glxMinor);
exit(0);
fprintf(stderr, "Invalid GLX version: major %d, minor %d\n",glxMajor,glxMinor);
exit(EXIT_FAILURE);
}
static int visual_attribs[] =
@ -573,7 +574,7 @@ if (res==0)
GLXFBConfig* fbc = glXChooseFBConfig(m_data->m_dpy, DefaultScreen(m_data->m_dpy), visual_attribs, &fbcount);
if (!fbc)
{
printf( "Failed to retrieve a framebuffer config\n" );
fprintf(stderr, "Failed to retrieve a framebuffer config\n" );
exit(1);
}
///don't use highest samples, it is really slow on some NVIDIA Quadro cards
@ -631,8 +632,8 @@ if (res==0)
if (!m_data->m_win)
{
printf("Cannot create window\n");
exit(0);
fprintf(stderr, "Cannot create window\n");
exit(EXIT_FAILURE);
}
MyXMapWindow(m_data->m_dpy, m_data->m_win);
@ -646,8 +647,8 @@ if (res==0)
printf("4\n");
if(m_data->m_vi == NULL) {
printf("\n\tno appropriate visual found\n\n");
exit(0);
fprintf(stderr, "\n\tno appropriate visual found\n\n");
exit(EXIT_FAILURE);
}
else {
printf("\n\tvisual %p selected\n", (void *)m_data->m_vi->visualid); /* %p creates hexadecimal output like in glxinfo */