1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 20:28:49 -05:00

Added basic error reporting to X11 port.

This commit is contained in:
Camilla Berglund 2010-09-09 21:52:31 +02:00
parent 922cd1011a
commit fa5d7488b8
4 changed files with 38 additions and 3 deletions

View File

@ -372,7 +372,10 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
// Get list of visuals // Get list of visuals
vislist = XGetVisualInfo(dpy, 0, &dummy, &viscount); vislist = XGetVisualInfo(dpy, 0, &dummy, &viscount);
if (vislist == NULL) if (vislist == NULL)
{
// TODO: Figure out which error this is
return 0; return 0;
}
rgbarray = (int*) malloc(sizeof(int) * viscount); rgbarray = (int*) malloc(sizeof(int) * viscount);
rgbcount = 0; rgbcount = 0;

View File

@ -79,13 +79,14 @@ static void glfw_atexit(void)
// Initialize X11 display // Initialize X11 display
//======================================================================== //========================================================================
static int initDisplay(void) static GLboolean initDisplay(void)
{ {
// Open display // Open display
_glfwLibrary.X11.display = XOpenDisplay(0); _glfwLibrary.X11.display = XOpenDisplay(0);
if (!_glfwLibrary.X11.display) if (!_glfwLibrary.X11.display)
{ {
fprintf(stderr, "Failed to open X display\n"); fprintf(stderr, "Failed to open X display\n");
_glfwSetError(GLFW_OPENGL_NOT_SUPPORTED);
return GL_FALSE; return GL_FALSE;
} }
@ -114,6 +115,7 @@ static int initDisplay(void)
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL)) if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
{ {
fprintf(stderr, "GLX not supported\n"); fprintf(stderr, "GLX not supported\n");
_glfwSetError(GLFW_OPENGL_NOT_SUPPORTED);
return GL_FALSE; return GL_FALSE;
} }
@ -123,6 +125,7 @@ static int initDisplay(void)
&_glfwLibrary.X11.glxMinor)) &_glfwLibrary.X11.glxMinor))
{ {
fprintf(stderr, "Unable to query GLX version\n"); fprintf(stderr, "Unable to query GLX version\n");
_glfwSetError(GLFW_OPENGL_NOT_SUPPORTED);
return GL_FALSE; return GL_FALSE;
} }

View File

@ -266,7 +266,10 @@ static void pollJoystickEvents(void)
int _glfwPlatformGetJoystickParam(int joy, int param) int _glfwPlatformGetJoystickParam(int joy, int param)
{ {
if (!_glfwJoy[joy].Present) if (!_glfwJoy[joy].Present)
{
// TODO: Figure out if this is an error
return 0; return 0;
}
switch (param) switch (param)
{ {
@ -296,7 +299,10 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
int i; int i;
if (!_glfwJoy[joy].Present) if (!_glfwJoy[joy].Present)
{
// TODO: Figure out if this is an error
return 0; return 0;
}
// Update joystick state // Update joystick state
pollJoystickEvents(); pollJoystickEvents();
@ -323,7 +329,10 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
int i; int i;
if (!_glfwJoy[joy].Present) if (!_glfwJoy[joy].Present)
{
// TODO: Figure out if this is an error
return 0; return 0;
}
// Update joystick state // Update joystick state
pollJoystickEvents(); pollJoystickEvents();

View File

@ -365,6 +365,8 @@ static Cursor createNULLCursor(Display* display, Window root)
XColor col; XColor col;
Cursor cursor; Cursor cursor;
// TODO: Add error checks
cursormask = XCreatePixmap(display, root, 1, 1, 1); cursormask = XCreatePixmap(display, root, 1, 1, 1);
xgc.function = GXclear; xgc.function = GXclear;
gc = XCreateGC(display, cursormask, GCFunction, &xgc); 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) if (!window->GLX.has_GLX_SGIX_fbconfig)
{ {
fprintf(stderr, "GLXFBConfigs are not supported by the X server\n"); fprintf(stderr, "GLXFBConfigs are not supported by the X server\n");
_glfwSetError(GLFW_NO_PIXEL_FORMAT);
return NULL; return NULL;
} }
} }
@ -432,6 +435,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
if (!count) if (!count)
{ {
fprintf(stderr, "No GLXFBConfigs returned\n"); fprintf(stderr, "No GLXFBConfigs returned\n");
_glfwSetError(GLFW_NO_PIXEL_FORMAT);
return NULL; return NULL;
} }
} }
@ -441,6 +445,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
if (!count) if (!count)
{ {
fprintf(stderr, "No GLXFBConfigs returned\n"); fprintf(stderr, "No GLXFBConfigs returned\n");
_glfwSetError(GLFW_NO_PIXEL_FORMAT);
return NULL; return NULL;
} }
} }
@ -448,7 +453,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
if (!result) if (!result)
{ {
fprintf(stderr, "Out of memory\n"); _glfwSetError(GLFW_OUT_OF_MEMORY);
return NULL; return NULL;
} }
@ -544,6 +549,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
if (fbconfig == NULL) if (fbconfig == NULL)
{ {
fprintf(stderr, "Unable to retrieve the selected GLXFBConfig\n"); fprintf(stderr, "Unable to retrieve the selected GLXFBConfig\n");
_glfwSetError(GLFW_INTERNAL_ERROR);
return GL_FALSE; return GL_FALSE;
} }
} }
@ -565,6 +571,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
XFree(fbconfig); XFree(fbconfig);
fprintf(stderr, "Unable to retrieve visual for GLXFBconfig\n"); fprintf(stderr, "Unable to retrieve visual for GLXFBconfig\n");
_glfwSetError(GLFW_INTERNAL_ERROR);
return GL_FALSE; 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 " fprintf(stderr, "OpenGL profile requested but GLX_ARB_create_context_profile "
"is unavailable\n"); "is unavailable\n");
_glfwSetError(GLFW_UNAVAILABLE_VERSION);
return GL_FALSE; return GL_FALSE;
} }
@ -643,6 +651,8 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
if (window->GLX.context == NULL) if (window->GLX.context == NULL)
{ {
fprintf(stderr, "Unable to create OpenGL context\n"); fprintf(stderr, "Unable to create OpenGL context\n");
// TODO: Handle all the various error codes here
_glfwSetError(GLFW_INTERNAL_ERROR);
return GL_FALSE; return GL_FALSE;
} }
@ -759,7 +769,11 @@ static GLboolean createWindow(_GLFWwindow* window,
); );
if (!window->X11.window) if (!window->X11.window)
{
// TODO: Handle all the various error codes here
_glfwSetError(GLFW_INTERNAL_ERROR);
return GL_FALSE; return GL_FALSE;
}
} }
// Check whether an EWMH-compliant window manager is running // Check whether an EWMH-compliant window manager is running
@ -817,7 +831,10 @@ static GLboolean createWindow(_GLFWwindow* window,
{ {
XWMHints* hints = XAllocWMHints(); XWMHints* hints = XAllocWMHints();
if (!hints) if (!hints)
{
_glfwSetError(GLFW_OUT_OF_MEMORY);
return GL_FALSE; return GL_FALSE;
}
hints->flags = StateHint; hints->flags = StateHint;
hints->initial_state = NormalState; hints->initial_state = NormalState;
@ -830,7 +847,10 @@ static GLboolean createWindow(_GLFWwindow* window,
{ {
XSizeHints* hints = XAllocSizeHints(); XSizeHints* hints = XAllocSizeHints();
if (!hints) if (!hints)
{
_glfwSetError(GLFW_OUT_OF_MEMORY);
return GL_FALSE; return GL_FALSE;
}
hints->flags = 0; hints->flags = 0;
@ -1610,7 +1630,7 @@ void _glfwPlatformRefreshWindowParams(void)
if (fbconfig == NULL) if (fbconfig == NULL)
{ {
// This should never ever happen // 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. " fprintf(stderr, "Cannot find known GLXFBConfig by ID. "
"This cannot happen. Have a nice day.\n"); "This cannot happen. Have a nice day.\n");
abort(); abort();