I've written a little DGA driver for my portable graphics library and it
seems to work fine, except that every time I exit a program that uses
it, I get a segfault:
Using DGA version 1.0
video memory unprotecting
MemBase = 0x401a9000, Width = 1024, BankSize = 2097152
Running at 1024x768x16
video memory protecting
Segmentation fault
If anybody can tell me how I can get rid of this, I'd be very grateful.
For completeness I will include a few relavent functions. You'll notice
I don't support banking yet... that's simply because I haven't gotten to
that stage. My card doesn't require banking, so it's currently not a
problem.
int detect(void) {
int major, minor, event_base, error_base;
// Try to connect to the X Server
display = XOpenDisplay(NULL);
if( display == NULL ) return 1;
if(!XF86DGAQueryVersion(display,&major,&minor)) {
printf("DGA version query failed\n");
return 1;
}
if(!XF86DGAQueryExtension(display,&event_base,&error_base)) {
printf("DGA extension query failed\n");
return 1;
}
// Fail if the extension version in the server is too old
if(major < 1 || (major == 1 && minor < 0)) {
printf("DGA extension is too old, get version 1.0 or higher\n");
return 1;
}
else printf("Using DGA version %d.%d", major, minor);
// Flag that we're using the MIT-SHM driver
petal.magic = DGA;
return 0;
int set_mode(char *window_name, int x, int y, int bpp) {Quote:}
XSetWindowAttributes xswa;
int ram, mem_size;
unsigned long mask;
int width, height;
XF86DGAGetViewPortSize(display, DefaultScreen(display), &width,
&height);
screen = DefaultScreenOfDisplay(display);
gc = XDefaultGC(display,DefaultScreen(display));
// override redirect tells the window manger to just ignore us
xswa.override_redirect = True;
xswa.event_mask = ButtonPressMask | ButtonReleaseMask |
ButtonMotionMask |
StructureNotifyMask | KeyPressMask | KeyReleaseMask;
xswa.background_pixel = BlackPixelOfScreen(screen);
mask = CWEventMask | CWOverrideRedirect | CWBackPixel;
// Create the window
printf("Creating window\n");
window = XCreateWindow(display, DefaultRootWindow(display), 0, 0,
width, height, 0, CopyFromParent, InputOutput,
CopyFromParent, mask, &xswa);
// Setup some properties
// XSetStandardProperties(display, window, window_name, window_name,
None, NULL, 0, NULL);
if(!window) {
printf("Unable to open window.\n");
return 1;
}
XMapWindow(display,window);
XRaiseWindow(display,window);
XF86DGAGetVideo(display, DefaultScreen(display), &address,
&bytes_per_line, &bank_size, &ram);
XF86DGADirectVideo(display, DefaultScreen(display),
XF86DGADirectGraphics /*| XF86DGADirectMouse |
XF86DGADirectKeyb*/);
printf("MemBase = 0x%x, Width = %i, BankSize = %i\n", address,
bytes_per_line, bank_size);
if(bank_size < (ram * 1024)) {
printf("Banked memory... ");
XF86DGASetVidPage(display,DefaultScreen(display),0);
}
printf("Setting viewport\n");
XF86DGASetViewPort(display,DefaultScreen(display),0,0);
// Setup some info about the mode we're in
petal.max_x = width;
petal.max_y = height;
petal.bpp = DefaultDepthOfScreen(screen);
if(petal.bpp == 15) petal.size = (width * height) << 1;
else petal.size = width * height * (petal.bpp >> 3);
return 0;
void deinit(void) {Quote:}
// give control back to the X server
XF86DGADirectVideo(display,DefaultScreen(display),0);
// and delete our window, etc.
XFreeGC(display, gc);
XDestroyWindow(display, window);
XCloseDisplay(display);
Thanks again,Quote:}
Jeff
PS: Please reply via email where possible.
--------------------------------------------
- Code X Software -
Programming to a Higher Power
web: http://www.execulink.com/~pweeks/
--------------------------------------------