PDA

View Full Version : Crash during OpenGL context creation



PaladinOfKaos
18th January 2008, 17:54
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)
{
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();
}
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

*Yes, I know this is a KDE program, but the problem appears to be in Qt

rbp
13th May 2009, 07:39
hello,

I know this was a long time ago, but did you ever figure out the context problem?

On my system (Windows XP, Qt 4.5.1) I found setting the context manually does not work and the only way to enable multisampling was through the constructor:

MyWidget:: MyWidget(QWidget *parent):QGLWidget(QGLFormat(QGL::SampleBuffers), parent)


I got the hint from this article that setContext() has problems: http://doc.trolltech.com/qq/qq06-glimpsing.html

hope that helps someone,
Richard