From: Geng, X. (NIH/N. [C] <ge...@ni...> - 2009-12-05 16:48:25
|
-----Original Message----- From: Brian Paul [mailto:br...@vm...] Sent: Friday, December 04, 2009 10:14 AM To: Geng, Xiujuan (NIH/NIDA) [C] Cc: mes...@li... Subject: Re: [Mesa3d-users] offscreen render segmentation fault with mesa 7.7 Geng, Xiujuan (NIH/NIDA) [C] wrote: > Hi, > > I'm new to mesa and openGL. I'm trying to do offscreen rendering on a 64bit Suse Linux machine. > > I started from a mesa demo code progs/osdemos/osdemo.c. I copied the main part below: > > /* Create an RGBA-mode context */ > #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 > /* specify Z, stencil, accum sizes */ > ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL ); > #else > ctx = OSMesaCreateContext( OSMESA_RGBA, NULL ); > #endif > if (!ctx) { > printf("OSMesaCreateContext failed!\n"); > return 0; > } > > /* Allocate the image buffer */ > buffer = malloc( Width * Height * 4 * sizeof(GLubyte) ); > if (!buffer) { > printf("Alloc image buffer failed!\n"); > return 0; > } > > /* Bind the buffer to the context and make it current */ > if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) { > printf("OSMesaMakeCurrent failed!\n"); > return 0; > } > > { > int z, s, a; > glGetIntegerv(GL_DEPTH_BITS, &z); > glGetIntegerv(GL_STENCIL_BITS, &s); > glGetIntegerv(GL_ACCUM_RED_BITS, &a); > printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a); > } > render_image(); > > I compiled the code with no problem: > gcc osdemo.c -lglut -lGLU -lOSMesa -lm -o osdemo > > But when I run it: > ./osdemo output.ppm 400 400 > > It gave me a seg fault. I used gdb to debug it, and the error message is: > > (gdb) run > Starting program: /data/380/gengx/tools/Mesa-7.5.1/progs/osdemos/osdemo output.ppm 400 400 > [Thread debugging using libthread_db enabled] > > Program received signal SIGSEGV, Segmentation fault. > glGetIntegerv () at ../../../src/mesa/x86-64/glapi_x86-64.S:9444 > 9444 movq 2104(%rax), %r11 > Current language: auto; currently asm > > Our own offscreen code (also using " OSMesaCreateContextExt " and " OSMesaMakeCurrent ") faced the same segmentation problem. Basically it gave a segmentation at whatever gl routine first called in the code. > > We are currently using mesa7.7. > > Any suggestion is appreciated! Thanks. Can you run w/ valgrind and see if that finds anything? Does the original osdemo.c work properly? Maybe try disabling x86-64 optimizations or a debug build of Mesa. -Brian Brian, Thanks for the suggestion. I got the seg fault from the original osdemo.c. I ran it with valgrind, and didn't find anything particular. We also ran the same osdemo.c code using Mesa7.4 on Ubuntu 9.04, it gave the same segmentation fault. But if I modify the demo code to do on-screen rendering, e.g., using glutCreateWindow and render the image to the window instead of doing off-screen render with "OSMesaCreateContextExt" and "OSMesaMakeCurrent", it works without any segmentation fault. We built mesa with a regular version and a debug version. The library is under /usr/lib/debug/usr/lib64/libOSMesa.so.7.7.0.debug I assume I compiled the demo code using the debug build of mesa. Here is the command I used to compile osdemo: gcc -g osdemo.c -lglut -lGLU -lOSMesa -lm -o osdemo The gdb gave the following error message: Program received signal SIGSEGV, Segmentation fault. glGetIntegerv () at ../../../src/mesa/x86-64/glapi_x86-64.S:9444 9444 movq 2104(%rax), %r11 Is it possible that there's some bug in OSMesaCreateContextExt or OSMesaMakeCurrent? I really need off-screen rendering. Thanks again. Xiujuan |