Hi, we have found an issue with mesa 6.5 and CVS mesa.
It seems that creating a context, then deleting it,
then creating a new one causes a crash.
Here is a simple VTK example:
vtkRenderWindow ren
ren Render
ren Delete
vtkRenderWindow ren
ren Render
ren Delete
We have also created a minimum glx/X/GL code from VTK that demonstrates the
problem.
It does not crash but exits with
X Error of failed request: BadValue (integer parameter out of range for
operation)
Major opcode of failed request: 78 (X_CreateColormap)
Value in failed request: 0xff00
Serial number of failed request: 8
Current serial number in output stream: 13
However, running the executable in valgrind produces the following:
==25222== Invalid read of size 4
==25222== at 0x40264806: XSync (in /usr/X11R6/lib/libX11.so.6.2)
==25222== by 0x405E5E94: XMesaGarbageCollect (xm_api.c:2570)
==25222== by 0x405E2166: Fake_glXCreateContext (fakeglx.c:1301)
==25222== by 0x405E17AE: glXCreateContext (glxapi.c:167)
==25222== by 0x80492DA: vtkWindow::CreateAWindow() (test.cxx:259)
==25222== by 0x804941E: vtkWindow::Render() (test.cxx:75)
==25222== by 0x8048D8D: main (test.cxx:103)
==25222== Address 0x420FB53C is 1232 bytes inside a block of size 1336 free'd
==25222== at 0x4002857D: free (vg_replace_malloc.c:186)
==25222== by 0x4025A3BD: _XFreeDisplayStructure (in
/usr/X11R6/lib/libX11.so.6.2)
==25222== by 0x402477C5: XCloseDisplay (in /usr/X11R6/lib/libX11.so.6.2)
==25222== by 0x8048EF3: vtkWindow::Destroy() (test.cxx:143)
==25222== by 0x80493E4: vtkWindow::~vtkWindow() (test.cxx:34)
==25222== by 0x8048D53: main (test.cxx:98)
==25222==
...
This happens when the second context is created. This is also exactly where VTK
crashes.
The program follows:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include <stdio.h>
#include <X11/Xlib.h> // Needed for X types used in the public interface
#include <X11/Xutil.h> // Needed for X types used in the public interface
#include <iostream>
using namespace std;
#define vtkErrorMacro(a) cout << "error: " a << endl;
#define vtkWarningMacro(a) cout << "warning: " a << endl;
extern "C" {int vtkXError(Display *display, XErrorEvent *err)
{
// cause a segfault
*(float *)(0x01) = 1.0;
return 1;
}}
class vtkWindow
{
public:
vtkWindow()
{
this->DisplayId = 0;
this->ParentId = (Window) NULL;
this->WindowId = (Window) NULL;
this->ColorMap = (Colormap) 0;
this->ContextId = 0;
}
~vtkWindow()
{
this->Destroy();
}
void CreateAWindow();
void MakeCurrent()
{
if (this->DisplayId)
{
//XSynchronize(this->DisplayId,1);
}
//XSetErrorHandler(vtkXError);
glXMakeCurrent(this->DisplayId,this->WindowId,this->ContextId);
}
void OpenGLInit()
{
glMatrixMode( GL_MODELVIEW );
glDepthFunc( GL_LEQUAL );
glEnable( GL_DEPTH_TEST );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// initialize blending for transparency
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable(GL_BLEND);
glDisable(GL_POINT_SMOOTH);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_POLYGON_SMOOTH);
glEnable(GL_NORMALIZE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glAlphaFunc(GL_GREATER,0);
}
void CopyResultFrame()
{
glFlush();
glXSwapBuffers(this->DisplayId, this->WindowId);
cout << "glXSwapBuffers "<< endl;
}
void Render()
{
this->CreateAWindow();
this->MakeCurrent();
}
void Destroy();
XVisualInfo *GetDesiredVisualInfo();
protected:
Display* DisplayId;
int OwnWindow;
Window WindowId;
Window ParentId;
Colormap ColorMap;
GLXContext ContextId;
};
int main (int argc, char* argv[])
{
{
vtkWindow *a = new vtkWindow;
a->Render();
delete a;
}
{
vtkWindow *b = new vtkWindow;
b->Render();
delete b;
}
{
vtkWindow *b = new vtkWindow;
b->Render();
delete b;
}
{
vtkWindow *b = new vtkWindow;
b->Render();
delete b;
}
return 0;
}
void vtkWindow::Destroy()
{
this->MakeCurrent();
if(this->ContextId)
{
glFinish();
glXDestroyContext(this->DisplayId, this->ContextId);
this->ContextId = NULL;
}
// then close the old window if we own it
if (this->DisplayId && this->WindowId)
{
XDestroyWindow(this->DisplayId,this->WindowId);
this->WindowId = (Window)NULL;
}
// if we create the display, we'll delete it
if (this->DisplayId)
{
XCloseDisplay(this->DisplayId);
this->DisplayId = NULL;
}
}
XVisualInfo *vtkXOpenGLRenderWindowTryForVisual(Display *DisplayId,
int doublebuff, int stereo,
int multisamples,
int alphaBitPlanes)
{
int index;
static int attributes[50];
// setup the default stuff we ask for
index = 0;
attributes[index++] = GLX_RGBA;
attributes[index++] = GLX_RED_SIZE;
attributes[index++] = 1;
attributes[index++] = GLX_GREEN_SIZE;
attributes[index++] = 1;
attributes[index++] = GLX_BLUE_SIZE;
attributes[index++] = 1;
attributes[index++] = GLX_DEPTH_SIZE;
attributes[index++] = 1;
if (alphaBitPlanes)
{
attributes[index++] = GLX_ALPHA_SIZE;
attributes[index++] = 1;
}
if (doublebuff)
{
attributes[index++] = GLX_DOUBLEBUFFER;
}
if (stereo)
{
// also try for STEREO
attributes[index++] = GLX_STEREO;
}
if (multisamples)
{
#ifdef GLX_SAMPLE_BUFFERS_SGIS
attributes[index++] = GLX_SAMPLE_BUFFERS_SGIS;
attributes[index++] = 1;
attributes[index++] = GLX_SAMPLES_SGIS;
attributes[index++] = multisamples;
#endif
}
attributes[index++] = None;
return glXChooseVisual(DisplayId, DefaultScreen(DisplayId), attributes );
}
void vtkWindow::CreateAWindow()
{
XVisualInfo *v, matcher;
XSetWindowAttributes attr;
int x, y, width, height, nItems;
XWindowAttributes winattr;
XSizeHints xsh;
xsh.flags = USSize;
xsh.flags |= USPosition;
xsh.x = 0;
xsh.y = 0;
x = 0;
y = 0;
width = 300;
height = 300;
xsh.width = width;
xsh.height = height;
// get the default display connection
if (!this->DisplayId)
{
this->DisplayId = XOpenDisplay((char *)NULL);
if (this->DisplayId == NULL)
{
vtkErrorMacro(<< "bad X server connection.\n");
}
}
attr.override_redirect = False;
v = vtkXOpenGLRenderWindowTryForVisual(this->DisplayId,
1,
0, 0, 0);
this->ColorMap = XCreateColormap(this->DisplayId,
RootWindow( this->DisplayId, v->screen),
v->visual, AllocNone );
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = this->ColorMap;
attr.event_mask = StructureNotifyMask | ExposureMask;
this->ParentId = RootWindow(this->DisplayId, v->screen);
this->WindowId =
XCreateWindow(this->DisplayId,
this->ParentId,
x, y, width, height, 0, v->depth, InputOutput, v->visual,
CWBackPixel | CWBorderPixel | CWColormap |
CWOverrideRedirect | CWEventMask,
&attr);
XStoreName(this->DisplayId, this->WindowId, "vtk");
XSetNormalHints(this->DisplayId,this->WindowId,&xsh);
// RESIZE THE WINDOW TO THE DESIRED SIZE
XResizeWindow(this->DisplayId,this->WindowId, 300, 300);
XSync(this->DisplayId,False);
if (!this->ContextId)
{
this->ContextId =
glXCreateContext(this->DisplayId, v, 0, GL_TRUE);
}
if(!this->ContextId)
{
vtkErrorMacro("Cannot create GLX context. Aborting.");
abort();
}
// free the visual info
if (v)
{
XFree(v);
}
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev