Why does glVertexAttribPointer/glDrawArrays crash here (only with certain drivers/GPUs)?
-
I don't know if you can call this forgiving. Interpreting an offset as an absolute pointer (what the desktop Nvidia driver apparently does) seems like something completely different...
Anyway this code still crashes which uses the same methods in the same order as the example in the documentation I referred to above:
(m_program refers to my QOpenGLShaderProgram from the initialization in my first post)
@void OpenGLWindow::render()
{
static const GLfloat colorBg[] = {1.0f, 0.0f, 0.0f, 1.0f};
glClearBufferfv(GL_COLOR, 0, colorBg);static GLfloat const triangleVertices[] = { 0.8f, 0.8f, 0.0f, 1.0f, 0.8f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; static const int vertexLocation = m_program.attributeLocation("vertex"); m_program.enableAttributeArray(vertexLocation); m_program.setAttributeArray(vertexLocation, triangleVertices, 4); glDrawArrays(GL_TRIANGLES, 0, 3); m_program.disableAttributeArray(vertexLocation);
}@
-
mmmm what if you try :
glDrawArrays(GL_TRIANGLES, 0, 1); ? -
It still crashes. It doesn't even draw a point when I change to GL_POINTS as it crashes at the vertex fetching stage. Of course I can use setAtrributeValue in this simple case but then I can't pass vertex data for multiple vertices to the shader. The second alternative is using a buffer like you suggested but then I don't get why this setAttributeArray method exists if it doesn't work consistently. Again this code works on my desktop GPU without a problem but I just had the chance to try it on a workstation at my job which uses a Nvidia NVS300 card with a Quadra/NVS driver and it also crashes.
-
mmmmm that s weird then all my guesses expired, try to do that with the buffer if it solve the problem if so we can assume is a qt problem and maybe you can flag it as a bug.
If not then it might be something driver related? -
Ok. I get why using the Qt SetAttributeArray method also crashes. I had a look in the source of the QOpenGLShaderProgram and it does nothing else than calling the glVertexAttribPointer OpenGL method I used in my first example.
@void QOpenGLShaderProgram::setAttributeArray (int location, const GLfloat *values, int tupleSize, int stride)
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
if (location != -1) {
d->glfuncs->glVertexAttribPointer(location, tupleSize, GL_FLOAT, GL_FALSE, stride, values);
}@So I guess either it is ok to use glVertexAttribPointer in this way and it's a driver bug or it is not ok to do this and Qt should drop these methods (or implement them using a buffer) and therefore it's a bug in Qt.
Somebody with a bit more OpenGL experience should be able to answer this problem... Do you think I should open a bug ticket for Qt and let them decide on which side the problem is? -
I was reading around of other people having trouble with intel grapichs and opengl. Do you have a discrete card on your laptop to switch on and see if keeps crasing ?
Yes might be worth to flag it to the qt guys
-
I was just able to test the code on a workstation at my job with a Nvidia (Quadro) NVS300 graphics card that of course uses a Qudrao driver instead of the GeForce driver and it also crashed. But I changed some things in the code between testing it at home and at the workstation to see whether it fixes the problem on my laptop. So I'll wait reporting this issue until I verified that it still works at home and I didn't mess up something else. (But this is highly unlikely because it's still nearly exactly the same code as the example in the Qt documentation shows)
-
Keep me posted man I am quite curious now tx
-
I'll do so! Maybe the OpenGL glVertexAttribPointer method is really not intended to be used in this way (all the books just describe the pointer to be an offset inside of an user created buffer). So the programmers of Qt might just got it wrong like I did and never noticed because some drivers accept it...
-
It still works correctly on my home PC. I reported the problem here: https://bugreports.qt-project.org/browse/QTBUG-40150
-
I got the same problem. I solved it by using this invocation ordering:
setAttributeArray(0,...);
enableAttributeArray(0);
glDrawArrays();
disableAttributeArray(0);It worked. I do this for every object I draw.
Regards. -
I got the same problem. I solved it by using this invocation ordering:
setAttributeArray(0,...);
enableAttributeArray(0);
glDrawArrays();
disableAttributeArray(0);It worked. I do this for every object I draw.
Regards.