Segfaults using OpenGL on udoobuntu

Discussion in 'Troubleshooting' started by mueberheide, Oct 28, 2014.

  1. mueberheide

    mueberheide New Member

    Joined:
    Oct 23, 2014
    Messages:
    1
    Likes Received:
    0
    Hi,

    I am working on a project which is going to use opengl on the udoo. I encounter segfaults from some methods which appear to be coming from the vivante_dri.so. The same code runs fine under arch, ubuntu and debian on a normal pc (and valgrind does not detect any memoryissues).

    The first segfaults occures trying to get the shader compilation logs:

    Code:
    Program received signal SIGSEGV, Segmentation fault.
    strlen () at ../ports/sysdeps/arm/strlen.S:29
    29../ports/sysdeps/arm/strlen.S: No such file or directory.
    (gdb) bt
    #0  strlen () at ../ports/sysdeps/arm/strlen.S:29
    #1  0x2b004984 in __glim_GetShaderiv () from /usr/lib/dri/vivante_dri.so
    #2  0x2abbe3bc in glGetShaderiv ()
       from /usr/lib/arm-linux-gnueabihf/libGL.so.1
    A further segfault is thrown by glBindAttribLocation:

    Code:
    Program received signal SIGSEGV, Segmentation fault.
    0x2b0252e0 in __glChipBindAttributeLocation () from /usr/lib/dri/vivante_dri.so
    (gdb) bt
    #0  0x2b0252e0 in __glChipBindAttributeLocation () from /usr/lib/dri/vivante_dri.so
    #1  0x2b005324 in __glim_BindAttribLocation () from /usr/lib/dri/vivante_dri.so
    #2  0x2abbe628 in glBindAttribLocation () from /usr/lib/arm-linux-gnueabihf/libGL.so.1

    Uname returns: Linux udoobuntu 3.0.35 #10 SMP PREEMPT Wed Jul 30 18:16:10 CEST 2014 armv7l armv7l armv7l GNU/Linux

    Code reproducing the problem appended below (as *.cpp is not allowed for attachments). Compile with
    Code:
    gcc minimalGL.cpp -lGL -lglut -lGLEW -lstdc++

    I fear the problem might be caused by an old version of udoobuntu or corrupted libs. So any hint is welcome.

    Kind regards,
    Matthias

    Code:
     
    #include <GL/glew.h>
    #include <GL/glut.h>
    
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    
    #include <iostream>
    
    //programs
    GLuint regProg;
    
    
    const GLfloat quad[4*3] = {
       /* down right */
       -0.95, -0.95,  0.0,
       0.95, -0.95,  0.0,
       -0.95,  0.95,  0.0,
       0.95,  0.95,  0.0,
    };
    const GLfloat texCoords[4*2] = {
       0.f,  1.f,
       1.f,  1.f,
       0.f,  0.f,
       1.f,  0.f,
    };
    
    
    
    ////////////////////////////////////////////////////////////////////////////////
    
    void printShaderLog(GLuint shad)
    {
        GLint infoLogLength = 0;
        GLsizei charsWritten  = 0;
        GLchar *infoLog;
        
        glGetShaderiv(shad, GL_INFO_LOG_LENGTH, &infoLogLength);
        
        if (infoLogLength > 0)
        {
            infoLog = new char[infoLogLength];
            glGetShaderInfoLog(shad, infoLogLength, &charsWritten, infoLog);
    		printf("%s\n",infoLog);
            delete[] infoLog;
        }
    }
    
    void printProgramLog(GLuint prog)
    {
        GLint infoLogLength = 0;
        GLsizei charsWritten  = 0;
        GLchar *infoLog;
        
        glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &infoLogLength);
        
        if (infoLogLength > 0)
        {
            infoLog = new char[infoLogLength];
            glGetProgramInfoLog(prog, infoLogLength, &charsWritten, infoLog);
    		printf("%s\n",infoLog);
            delete[] infoLog;
        }
    }
    
    
    ////////////////////////////////////////////////////////////////////////////////
    
    
    void renderScene(void) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear buffer 
        glUseProgram(regProg);
    
        glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, quad );
        glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 0, texCoords );
        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(1);
       
        glDrawArrays( GL_TRIANGLE_STRIP, 0, 4);
    
        glutSwapBuffers();
    }
    
    
    int main(int argc, char **argv) {
      //Setup glut and glew
      glutInit(&argc, argv);
      glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
      glutInitWindowPosition(20,20);
      glutInitWindowSize(800, 600);
      glutCreateWindow("GLSL-Test");
      
      glutDisplayFunc(renderScene);
      glutIdleFunc(renderScene);
        
      glewInit();
    
      glEnable(GL_DEPTH_TEST);
         
      glClearColor(0.0,0.0,0.0,1.0);
        
        
      if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader&&GL_EXT_geometry_shader4)//)
        printf("Ready for GLSL\n");
      else {
        printf("No GLSL support\n");
        exit(1);
      }
    
      //Setup shaders
      GLuint v,f;
      v = glCreateShader(GL_VERTEX_SHADER);
      f = glCreateShader(GL_FRAGMENT_SHADER);
    
      const char* vv = "attribute vec4 vPosition;\
    attribute vec2 per_vertex_tex_coord;\
    varying vec2 tex_coord;\
    void main(){ \
     gl_Position = vPosition; \
     tex_coord = per_vertex_tex_coord;\
    } ";
    
      const char* ff = "varying vec2 tex_coord;\
    uniform sampler2D tex;\
    void main(){ \
      gl_FragColor.rg =  tex_coord; \
      gl_FragColor.ba = vec2(0.0,1.1);\
     }";
        
      glShaderSource(v, 1, &vv,NULL);
      glShaderSource(f, 1, &ff,NULL);
        
      glCompileShader(v);
      glCompileShader(f);
        
      printShaderLog(v);
      printShaderLog(f);
        
      regProg = glCreateProgram();
      glAttachShader(regProg,v);
      glAttachShader(regProg,f);
        
      glLinkProgram(regProg);
      printProgramLog(regProg);
    
    
      //MainLoop
      glutMainLoop();
      return 0;
    }
    
    
     

Share This Page