From fa5d7488b884bd4236689dc0dba2ea3de44e88fc Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Sep 2010 21:52:31 +0200 Subject: [PATCH] Added basic error reporting to X11 port. --- src/x11/x11_fullscreen.c | 3 +++ src/x11/x11_init.c | 5 ++++- src/x11/x11_joystick.c | 9 +++++++++ src/x11/x11_window.c | 24 ++++++++++++++++++++++-- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/x11/x11_fullscreen.c b/src/x11/x11_fullscreen.c index c59e1e4c..dbad9801 100644 --- a/src/x11/x11_fullscreen.c +++ b/src/x11/x11_fullscreen.c @@ -372,7 +372,10 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) // Get list of visuals vislist = XGetVisualInfo(dpy, 0, &dummy, &viscount); if (vislist == NULL) + { + // TODO: Figure out which error this is return 0; + } rgbarray = (int*) malloc(sizeof(int) * viscount); rgbcount = 0; diff --git a/src/x11/x11_init.c b/src/x11/x11_init.c index 12af4f3c..150c94ae 100644 --- a/src/x11/x11_init.c +++ b/src/x11/x11_init.c @@ -79,13 +79,14 @@ static void glfw_atexit(void) // Initialize X11 display //======================================================================== -static int initDisplay(void) +static GLboolean initDisplay(void) { // Open display _glfwLibrary.X11.display = XOpenDisplay(0); if (!_glfwLibrary.X11.display) { fprintf(stderr, "Failed to open X display\n"); + _glfwSetError(GLFW_OPENGL_NOT_SUPPORTED); return GL_FALSE; } @@ -114,6 +115,7 @@ static int initDisplay(void) if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL)) { fprintf(stderr, "GLX not supported\n"); + _glfwSetError(GLFW_OPENGL_NOT_SUPPORTED); return GL_FALSE; } @@ -123,6 +125,7 @@ static int initDisplay(void) &_glfwLibrary.X11.glxMinor)) { fprintf(stderr, "Unable to query GLX version\n"); + _glfwSetError(GLFW_OPENGL_NOT_SUPPORTED); return GL_FALSE; } diff --git a/src/x11/x11_joystick.c b/src/x11/x11_joystick.c index de6aed6a..3a2f3dc1 100644 --- a/src/x11/x11_joystick.c +++ b/src/x11/x11_joystick.c @@ -266,7 +266,10 @@ static void pollJoystickEvents(void) int _glfwPlatformGetJoystickParam(int joy, int param) { if (!_glfwJoy[joy].Present) + { + // TODO: Figure out if this is an error return 0; + } switch (param) { @@ -296,7 +299,10 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) int i; if (!_glfwJoy[joy].Present) + { + // TODO: Figure out if this is an error return 0; + } // Update joystick state pollJoystickEvents(); @@ -323,7 +329,10 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int i; if (!_glfwJoy[joy].Present) + { + // TODO: Figure out if this is an error return 0; + } // Update joystick state pollJoystickEvents(); diff --git a/src/x11/x11_window.c b/src/x11/x11_window.c index 0e847dea..60835c0d 100644 --- a/src/x11/x11_window.c +++ b/src/x11/x11_window.c @@ -365,6 +365,8 @@ static Cursor createNULLCursor(Display* display, Window root) XColor col; Cursor cursor; + // TODO: Add error checks + cursormask = XCreatePixmap(display, root, 1, 1, 1); xgc.function = GXclear; gc = XCreateGC(display, cursormask, GCFunction, &xgc); @@ -419,6 +421,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (!window->GLX.has_GLX_SGIX_fbconfig) { fprintf(stderr, "GLXFBConfigs are not supported by the X server\n"); + _glfwSetError(GLFW_NO_PIXEL_FORMAT); return NULL; } } @@ -432,6 +435,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (!count) { fprintf(stderr, "No GLXFBConfigs returned\n"); + _glfwSetError(GLFW_NO_PIXEL_FORMAT); return NULL; } } @@ -441,6 +445,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (!count) { fprintf(stderr, "No GLXFBConfigs returned\n"); + _glfwSetError(GLFW_NO_PIXEL_FORMAT); return NULL; } } @@ -448,7 +453,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); if (!result) { - fprintf(stderr, "Out of memory\n"); + _glfwSetError(GLFW_OUT_OF_MEMORY); return NULL; } @@ -544,6 +549,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G if (fbconfig == NULL) { fprintf(stderr, "Unable to retrieve the selected GLXFBConfig\n"); + _glfwSetError(GLFW_INTERNAL_ERROR); return GL_FALSE; } } @@ -565,6 +571,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G XFree(fbconfig); fprintf(stderr, "Unable to retrieve visual for GLXFBconfig\n"); + _glfwSetError(GLFW_INTERNAL_ERROR); return GL_FALSE; } @@ -599,6 +606,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G { fprintf(stderr, "OpenGL profile requested but GLX_ARB_create_context_profile " "is unavailable\n"); + _glfwSetError(GLFW_UNAVAILABLE_VERSION); return GL_FALSE; } @@ -643,6 +651,8 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G if (window->GLX.context == NULL) { fprintf(stderr, "Unable to create OpenGL context\n"); + // TODO: Handle all the various error codes here + _glfwSetError(GLFW_INTERNAL_ERROR); return GL_FALSE; } @@ -759,7 +769,11 @@ static GLboolean createWindow(_GLFWwindow* window, ); if (!window->X11.window) + { + // TODO: Handle all the various error codes here + _glfwSetError(GLFW_INTERNAL_ERROR); return GL_FALSE; + } } // Check whether an EWMH-compliant window manager is running @@ -817,7 +831,10 @@ static GLboolean createWindow(_GLFWwindow* window, { XWMHints* hints = XAllocWMHints(); if (!hints) + { + _glfwSetError(GLFW_OUT_OF_MEMORY); return GL_FALSE; + } hints->flags = StateHint; hints->initial_state = NormalState; @@ -830,7 +847,10 @@ static GLboolean createWindow(_GLFWwindow* window, { XSizeHints* hints = XAllocSizeHints(); if (!hints) + { + _glfwSetError(GLFW_OUT_OF_MEMORY); return GL_FALSE; + } hints->flags = 0; @@ -1610,7 +1630,7 @@ void _glfwPlatformRefreshWindowParams(void) if (fbconfig == NULL) { // This should never ever happen - // TODO: Figure out what to do when this happens + // TODO: Flag this as an error and propagate up fprintf(stderr, "Cannot find known GLXFBConfig by ID. " "This cannot happen. Have a nice day.\n"); abort();