I'm having an interesting problem with OpenGL contexts in Qt 4.3.3 (Kubuntu 8.04).
When I try to customize the format, liks so:
MainWindow
::MainWindow(QWidget *parent
) : KXmlGuiWindow(parent)
{
qDebug("Setting up GL format...");
format.setAccum(false);
format.setAlpha(true);
format.setAlphaBufferSize(8);
format.setBlueBufferSize(8);
format.setDepth(true);
format.setDepthBufferSize(24);
format.setDirectRendering(true);
format.setDoubleBuffer(true);
format.setGreenBufferSize(8);
format.setOverlay(false);
format.setPlane(0);
format.setRedBufferSize(8);
format.setRgba(true);
format.setSampleBuffers(true);
format.setSamples(4);
format.setStencil(true);
format.setStencilBufferSize(8);
format.setStereo(false);
format.setSwapInterval(0);
qDebug("Creating Context...");
if(!context->create()) {
qWarning("Failed to create context...");
qDebug("Disabling multisampling...");
format.setSampleBuffers(false);
context->setFormat(format);
if(!context->create()) {
qFatal("Still can't create a context...");
exit(0);
}
}
qDebug("Creating preview widget...");
preview = new MaterialPreview(context);
setCentralWidget(preview);
setupGUI();
}
MainWindow::MainWindow(QWidget *parent)
: KXmlGuiWindow(parent)
{
QGLFormat format;
QGLContext *context;
qDebug("Setting up GL format...");
format.setAccum(false);
format.setAlpha(true);
format.setAlphaBufferSize(8);
format.setBlueBufferSize(8);
format.setDepth(true);
format.setDepthBufferSize(24);
format.setDirectRendering(true);
format.setDoubleBuffer(true);
format.setGreenBufferSize(8);
format.setOverlay(false);
format.setPlane(0);
format.setRedBufferSize(8);
format.setRgba(true);
format.setSampleBuffers(true);
format.setSamples(4);
format.setStencil(true);
format.setStencilBufferSize(8);
format.setStereo(false);
format.setSwapInterval(0);
qDebug("Creating Context...");
context = new QGLContext(format);
if(!context->create()) {
qWarning("Failed to create context...");
qDebug("Disabling multisampling...");
format.setSampleBuffers(false);
context->setFormat(format);
if(!context->create()) {
qFatal("Still can't create a context...");
exit(0);
}
}
qDebug("Creating preview widget...");
preview = new MaterialPreview(context);
setCentralWidget(preview);
setupGUI();
}
To copy to clipboard, switch view to plain text mode
I get a crash during the first call to context->create().
When I don't setup a custom format and context, and just create a QGLWidget, I don't have the crash.
In case you're curious, the odd bit with multisampling is just a test to see if I can actually setup a multisampled rendering context on my machine.
EDIT:
Here's the backtrace:
#0 0xb755dc35 in QX11Info::screen () from /usr/lib/libQtGui.so.4
#1 0xb6d31671 in QGLContext::tryVisual () from /usr/lib/libQtOpenGL.so.4
#2 0xb6d30529 in QGLContext::chooseVisual () from /usr/lib/libQtOpenGL.so.4
#3 0xb6d30984 in QGLContext::chooseContext () from /usr/lib/libQtOpenGL.so.4
#4 0xb6d062a4 in QGLContext::create () from /usr/lib/libQtOpenGL.so.4
#5 0x0804ca79 in MainWindow (this=0x80fdf80, parent=0x0) at mainwindow.cpp:39
#6 0x0804c778 in main (argc=1, argv=0xbfc0c574) at main.cpp:25
#0 0xb755dc35 in QX11Info::screen () from /usr/lib/libQtGui.so.4
#1 0xb6d31671 in QGLContext::tryVisual () from /usr/lib/libQtOpenGL.so.4
#2 0xb6d30529 in QGLContext::chooseVisual () from /usr/lib/libQtOpenGL.so.4
#3 0xb6d30984 in QGLContext::chooseContext () from /usr/lib/libQtOpenGL.so.4
#4 0xb6d062a4 in QGLContext::create () from /usr/lib/libQtOpenGL.so.4
#5 0x0804ca79 in MainWindow (this=0x80fdf80, parent=0x0) at mainwindow.cpp:39
#6 0x0804c778 in main (argc=1, argv=0xbfc0c574) at main.cpp:25
To copy to clipboard, switch view to plain text mode
*Yes, I know this is a KDE program, but the problem appears to be in Qt
Bookmarks