Results 1 to 7 of 7

Thread: A segmentation error when I get size of the std::vector

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default A segmentation error when I get size of the std::vector

    Hello!

    I have a segmentation error on the this string: size_t size = meshes.size();

    Qt Code:
    1. void meshLoader::draw(unsigned int programId)
    2. {
    3. size_t size = meshes.size();
    4.  
    5. for( unsigned int i = 0;i < meshes.size(); ++i )
    6. meshes[i].draw( programId );
    7. }
    To copy to clipboard, switch view to plain text mode 

    Please, run my application if you use Assimp. Or just see code
    Attached Files Attached Files
    Last edited by 8Observer8; 3rd December 2014 at 17:05.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: A segmentation error when I get size of the std::vector

    That usually means that "this" is not a valid instance.

    Check the creation of the meshLoader instance and if you call its method and not on some invalid pointer

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    8Observer8 (4th December 2014)

  4. #3
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: A segmentation error when I get size of the std::vector

    I don't understand why it occur. I have a global variable "globalGLFunctions":

    Qt Code:
    1. #include <QOpenGLFunctions_2_1>
    2.  
    3. // ...
    4.  
    5. QOpenGLFunctions_2_1 *globalGLFunctions;
    6.  
    7. // ...
    8.  
    9. Scene::Scene( QWidget *parent ) :
    10. QGLWidget( parent )
    11. {
    12. makeCurrent();
    13. globalGLFunctions = new QOpenGLFunctions_2_1;
    14. globalGLFunctions->initializeOpenGLFunctions();
    15. }
    16.  
    17. void mesh::draw(unsigned int programId)
    18. {
    19. //attribute vec3 vertex
    20. int vertex = globalGLFunctions->glGetAttribLocation(programId,"vertex"); //0
    21. int normal = globalGLFunctions->glGetAttribLocation(programId,"normal"); //1
    22. int tangent = globalGLFunctions->glGetAttribLocation(programId,"tangent"); //2
    23. int color = globalGLFunctions->glGetAttribLocation(programId,"color"); //3
    24. int UV = globalGLFunctions->glGetAttribLocation(programId,"UV"); //4
    25.  
    26. //texture0
    27. //texture1...
    28. std::string str="texture";
    29. for( size_t i=0;i<textures.size();i++)
    30. {
    31. globalGLFunctions->glActiveTexture(GL_TEXTURE0+i);
    32. globalGLFunctions->glBindTexture(GL_TEXTURE_2D,textures[i].id);
    33. globalGLFunctions->glUniform1i(globalGLFunctions->glGetUniformLocation(programId,(str+(char)(i+'0')).c_str()),i);
    34. }
    35.  
    36. globalGLFunctions->glBindBuffer(GL_ARRAY_BUFFER,VBO);
    37. globalGLFunctions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,IND);
    38.  
    39. globalGLFunctions->glEnableVertexAttribArray(vertex);
    40. globalGLFunctions->glVertexAttribPointer(vertex,3,GL_FLOAT,GL_FALSE,sizeof(vertexData),0);
    41.  
    42. globalGLFunctions->glEnableVertexAttribArray(normal);
    43. globalGLFunctions->glVertexAttribPointer(normal,3,GL_FLOAT,GL_FALSE,sizeof(vertexData),(void*)(3*sizeof(float)));
    44.  
    45. globalGLFunctions->glEnableVertexAttribArray(tangent);
    46. globalGLFunctions->glVertexAttribPointer(tangent,3,GL_FLOAT,GL_FALSE,sizeof(vertexData),(void*)(6*sizeof(float)));
    47.  
    48. globalGLFunctions->glEnableVertexAttribArray(color);
    49. globalGLFunctions->glVertexAttribPointer(color,3,GL_FLOAT,GL_FALSE,sizeof(vertexData),(void*)(9*sizeof(float)));
    50.  
    51. globalGLFunctions->glEnableVertexAttribArray(UV);
    52. globalGLFunctions->glVertexAttribPointer(UV,2,GL_FLOAT,GL_FALSE,sizeof(vertexData),(void*)(12*sizeof(float)));
    53.  
    54. globalGLFunctions->glDrawElements(GL_TRIANGLES,indices.size(),GL_UNSIGNED_INT,0);
    55.  
    56. globalGLFunctions->glDisableVertexAttribArray(vertex);
    57. globalGLFunctions->glDisableVertexAttribArray(normal);
    58. globalGLFunctions->glDisableVertexAttribArray(tangent);
    59. globalGLFunctions->glDisableVertexAttribArray(color);
    60. globalGLFunctions->glDisableVertexAttribArray(UV);
    61. globalGLFunctions->glBindBuffer(GL_ARRAY_BUFFER,0);
    62. globalGLFunctions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
    63. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Segmentation error! Please help!!!
    By phapha in forum Newbie
    Replies: 4
    Last Post: 26th October 2011, 17:01
  2. Segmentation error in run
    By kurrachow in forum Newbie
    Replies: 1
    Last Post: 21st April 2011, 13:13
  3. vector causing system error/crash
    By babygal in forum Newbie
    Replies: 9
    Last Post: 21st October 2010, 07:48
  4. vector of vector size
    By mickey in forum General Programming
    Replies: 5
    Last Post: 13th February 2007, 15:59
  5. runtime error <vector>
    By mickey in forum General Programming
    Replies: 10
    Last Post: 5th September 2006, 12:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.