Adam Yaxley Adam Yaxley - 1 year ago 115
C++ Question

Xlib Fatal IO Error: 11 (resource temporarily unavailable)

FIXED: The error is simply becuase I quit the application without closing the display using XCloseDisplay(). And the reason i didnt get anything appearing on the screen was because the values for width and height werent actually set so when it set the projection it set it to 0 by 0 or something strange like that. Thanks to datenwolf for helping me :)

I get this error when running my code:

XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
after 58 requests (58 known processed) with 0 events remaining.

I have looked everywhere on the internet and in the documentation but I can't find anything on what this means?

When I run the code I see the window, but nothing draws inside and when I quit the window I get the above error.

I'm not trying to do anything fancy. I have set the X window system up with OpenGL

I have a basic program like this:

#include <GL/gl.h>

#include <GL/glu.h>

// create window
bool success = paDisplay::init(640, 480);
if (!success)
std::cout << "oh noes";
while (1)
// do pre-frame tasks

// process the screen and draw

// do post-frame tasks

And here is the code for the paDisplay class:

#include <X11/X.h>

#include <X11/Xlib.h>

#include <GL/glx.h>

class paDisplay



// window information

static Display *dpy;

static Window win;

static GLXContext glc;

static XWindowAttributes gwa;

static XEvent xev;

static int width, height;
static int frame;

// event information

static bool EV_Resize, EV_KeyPress;

static KeySym EV_Key;

// functions

static void destroyWindow();


static bool init(int, int);
static void stepBegin();
static void stepEnd();

// window

static bool createWindow(int, int);
static void setTitle(std::string);

// events

static void pollEvents();

static bool eventResize() { return EV_Resize; }

static bool eventKeyPress() { return EV_KeyPress; }

static unsigned int getKey() { return EV_Key; }

// opengl
static void initOpenGL();

static void swapBuffers();

// quit

static void quit();

// window dimensions

static int getWidth() { return width; }

static int getHeight() { return height; }

// static variables
// window information

Display* paDisplay::dpy;

Window paDisplay::win;

GLXContext paDisplay::glc;

XWindowAttributes paDisplay::gwa;

XEvent paDisplay::xev;

int paDisplay::width;
int paDisplay::height;
int paDisplay::frame;

// event information

bool paDisplay::EV_Resize;
bool paDisplay::EV_KeyPress;

KeySym paDisplay::EV_Key;

// implementation

bool paDisplay::init(int w, int h)
if (createWindow(w, h))

time_t start = time(NULL);


// initialize frame counter

frame = 0;

return true;
return false;

void paDisplay::stepBegin()
// clear the screen



void paDisplay::stepEnd()
// start processing buffered opengl routines


// swap buffers


// implement dumb frames per second

usleep(1000000 / 60);

// increase frame counter

frame ++;

void paDisplay::initOpenGL()
// init OpenGL


glClearColor(1.0, 1.0, 1.0, 1.0);


glViewport(0, 0, width, height);



gluOrtho2D(0, (GLdouble) width, 0, (GLdouble) height);

void paDisplay::setTitle(std::string title)
XStoreName(dpy, win, title.c_str());

void paDisplay::quit()





void paDisplay::pollEvents()


// set defaults

EV_Resize = false;

EV_KeyPress = false;

while (XPending(dpy) > 0)


// get next event

XNextEvent(dpy, &xev);

switch (xev.type)


// window resized

case Expose:

/*EV_Resize = true;

XGetWindowAttributes(dpy, win, &gwa);

width = gwa.width;

height = gwa.height;
// resize OpenGL projection function

glViewport(0, 0, width, height);



gluOrtho2D(0, (GLdouble) width, 0, (GLdouble) height);*/


// a key was pressed

case KeyPress:

EV_KeyPress = true;

EV_Key = XLookupKeysym(&xev.xkey, 0);





void paDisplay::swapBuffers()


glXSwapBuffers(dpy, win);


bool paDisplay::createWindow(int w, int h)


Window root;


XVisualInfo *vi;

Colormap cmap;

XSetWindowAttributes swa;

dpy = XOpenDisplay(NULL);

if (dpy == NULL)

return false;

XSynchronize(dpy, true);

root = DefaultRootWindow(dpy);

vi = glXChooseVisual(dpy, 0, att);

if (vi == NULL)

return false;

cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);

swa.colormap = cmap;

swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;

win = XCreateWindow(dpy, root, 0, 0, w, h, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa);

XMapWindow(dpy, win);

XStoreName(dpy, win, "Pineapple");

glc = glXCreateContext(dpy, vi, NULL, GL_TRUE);

glXMakeCurrent(dpy, win, glc);

return true;


void paDisplay::destroyWindow()


glXMakeCurrent(dpy, None, NULL);

glXDestroyContext(dpy, glc);

XDestroyWindow(dpy, win);



Answer Source

The error is because I quit the application without closing the display using XCloseDisplay().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download