Results 1 to 7 of 7

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

  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 

  5. #4
    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

    Quote Originally Posted by anda_skoa View Post
    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,
    _
    Please, look at my "meshLoader instance" and say me where is my mistake:
    Qt Code:
    1. #include <QOpenGLFunctions_2_1>
    2. #include <QDir>
    3. #include <QFile>
    4. #include <vector>
    5. #include <iostream>
    6. #include "Scene.h"
    7. #include "MeshData.h"
    8. //#include "ObjLoader.h"
    9. #include <GL/glu.h>
    10. #include <assimp/Importer.hpp>
    11. #include <assimp/scene.h>
    12. #include <assimp/postprocess.h>
    13.  
    14. QOpenGLFunctions_2_1 *globalGLFunctions;
    15.  
    16. class mesh
    17. {
    18. std::vector<vertexData> data;
    19. std::vector<textureData> textures;
    20. std::vector<unsigned int> indices;
    21. unsigned int VBO;
    22. unsigned int IND;
    23. public:
    24. mesh(std::vector<vertexData>* vd,std::vector<unsigned int>* id,std::vector<textureData>* td=NULL);
    25. ~mesh();
    26. void draw(unsigned int programId);
    27. };
    28.  
    29. mesh::mesh(std::vector<vertexData>* vd,std::vector<unsigned int>* id,std::vector<textureData>* td)
    30. {
    31. data=*vd;
    32. indices=*id;
    33. if(td)
    34. textures=*td;
    35.  
    36. globalGLFunctions->glGenBuffers(1,&VBO);
    37. globalGLFunctions->glBindBuffer(GL_ARRAY_BUFFER,VBO);
    38. globalGLFunctions->glBufferData(GL_ARRAY_BUFFER,data.size()*sizeof(vertexData),
    39. &data[0],GL_STATIC_DRAW);
    40.  
    41.  
    42. globalGLFunctions->glGenBuffers(1,&IND);
    43. globalGLFunctions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,IND);
    44. globalGLFunctions->glBufferData(GL_ELEMENT_ARRAY_BUFFER,indices.size()*sizeof(unsigned int),&indices[0],GL_STATIC_DRAW);
    45.  
    46. globalGLFunctions->glBindBuffer(GL_ARRAY_BUFFER,0);
    47. globalGLFunctions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
    48. }
    49.  
    50. mesh::~mesh()
    51. {
    52. // glDeleteBuffers(1,&VBO);
    53. // glDeleteBuffers(1,&IND);
    54. }
    55.  
    56. void mesh::draw(unsigned int programId)
    57. {
    58. //attribute vec3 vertex
    59. int vertex = globalGLFunctions->glGetAttribLocation(programId,"vertex"); //0
    60. int normal = globalGLFunctions->glGetAttribLocation(programId,"normal"); //1
    61. int tangent = globalGLFunctions->glGetAttribLocation(programId,"tangent"); //2
    62. int color = globalGLFunctions->glGetAttribLocation(programId,"color"); //3
    63. int UV = globalGLFunctions->glGetAttribLocation(programId,"UV"); //4
    64.  
    65. //texture0
    66. //texture1...
    67. std::string str="texture";
    68. for( size_t i=0;i<textures.size();i++)
    69. {
    70. globalGLFunctions->glActiveTexture(GL_TEXTURE0+i);
    71. globalGLFunctions->glBindTexture(GL_TEXTURE_2D,textures[i].id);
    72. globalGLFunctions->glUniform1i(globalGLFunctions->glGetUniformLocation(programId,(str+(char)(i+'0')).c_str()),i);
    73. }
    74.  
    75. globalGLFunctions->glBindBuffer(GL_ARRAY_BUFFER,VBO);
    76. globalGLFunctions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,IND);
    77.  
    78. globalGLFunctions->glEnableVertexAttribArray(vertex);
    79. globalGLFunctions->glVertexAttribPointer(vertex,3,GL_FLOAT,GL_FALSE,sizeof(vertexData),0);
    80.  
    81. globalGLFunctions->glEnableVertexAttribArray(normal);
    82. globalGLFunctions->glVertexAttribPointer(normal,3,GL_FLOAT,GL_FALSE,sizeof(vertexData),(void*)(3*sizeof(float)));
    83.  
    84. globalGLFunctions->glEnableVertexAttribArray(tangent);
    85. globalGLFunctions->glVertexAttribPointer(tangent,3,GL_FLOAT,GL_FALSE,sizeof(vertexData),(void*)(6*sizeof(float)));
    86.  
    87. globalGLFunctions->glEnableVertexAttribArray(color);
    88. globalGLFunctions->glVertexAttribPointer(color,3,GL_FLOAT,GL_FALSE,sizeof(vertexData),(void*)(9*sizeof(float)));
    89.  
    90. globalGLFunctions->glEnableVertexAttribArray(UV);
    91. globalGLFunctions->glVertexAttribPointer(UV,2,GL_FLOAT,GL_FALSE,sizeof(vertexData),(void*)(12*sizeof(float)));
    92.  
    93. globalGLFunctions->glDrawElements(GL_TRIANGLES,indices.size(),GL_UNSIGNED_INT,0);
    94.  
    95. globalGLFunctions->glDisableVertexAttribArray(vertex);
    96. globalGLFunctions->glDisableVertexAttribArray(normal);
    97. globalGLFunctions->glDisableVertexAttribArray(tangent);
    98. globalGLFunctions->glDisableVertexAttribArray(color);
    99. globalGLFunctions->glDisableVertexAttribArray(UV);
    100. globalGLFunctions->glBindBuffer(GL_ARRAY_BUFFER,0);
    101. globalGLFunctions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
    102. }
    103.  
    104. class meshLoader
    105. {
    106. //std::vector<mesh*> meshes;
    107. std::vector<mesh> meshes;
    108. void recursiveProcess(aiNode* node,const aiScene* scene);
    109. void processMesh(aiMesh* mesh,const aiScene* scene);
    110. unsigned int loadTexture(const char* filename);
    111. public:
    112. meshLoader(const char* filename);
    113. ~meshLoader();
    114. void draw(unsigned int programId);
    115. std::vector<mesh*>& getMeshes();
    116. };
    117.  
    118. void meshLoader::recursiveProcess(aiNode* node,const aiScene* scene)
    119. {
    120. //process
    121. for( unsigned int i=0;i<node->mNumMeshes;i++)
    122. {
    123. aiMesh* mesh=scene->mMeshes[node->mMeshes[i]];
    124. processMesh(mesh,scene);
    125. }
    126.  
    127.  
    128.  
    129. //recursion
    130. for( unsigned int i=0;i<node->mNumChildren;i++)
    131. {
    132. recursiveProcess(node->mChildren[i],scene);
    133. }
    134. }
    135.  
    136. void meshLoader::processMesh(aiMesh* mesh,const aiScene* scene)
    137. {
    138. std::vector<vertexData> data;
    139. std::vector<unsigned int> indices;
    140. std::vector<textureData> textures;
    141.  
    142. aiColor4D col;
    143. aiMaterial* mat=scene->mMaterials[mesh->mMaterialIndex];
    144. aiGetMaterialColor(mat,AI_MATKEY_COLOR_DIFFUSE,&col);
    145. vector3d defaultColor(col.r,col.g,col.b);
    146.  
    147. for( unsigned int i=0;i<mesh->mNumVertices;i++)
    148. {
    149. vertexData tmp;
    150. vector3d tmpVec;
    151.  
    152. //position
    153. tmpVec.x=mesh->mVertices[i].x;
    154. tmpVec.y=mesh->mVertices[i].y;
    155. tmpVec.z=mesh->mVertices[i].z;
    156. tmp.position=tmpVec;
    157.  
    158. //normals
    159. tmpVec.x=mesh->mNormals[i].x;
    160. tmpVec.y=mesh->mNormals[i].y;
    161. tmpVec.z=mesh->mNormals[i].z;
    162. tmp.normal=tmpVec;
    163.  
    164.  
    165. //tangent
    166. if(mesh->mTangents)
    167. {
    168. tmpVec.x=mesh->mTangents[i].x;
    169. tmpVec.y=mesh->mTangents[i].y;
    170. tmpVec.z=mesh->mTangents[i].z;
    171. }else{
    172. tmpVec.x=1.0;
    173. tmpVec.y=tmpVec.z=0;
    174. }
    175. tmp.tangent=tmpVec;
    176.  
    177.  
    178. //colors
    179. if(mesh->mColors[0])
    180. {
    181. //!= material color
    182. tmpVec.x=mesh->mColors[0][i].r;
    183. tmpVec.y=mesh->mColors[0][i].g;
    184. tmpVec.z=mesh->mColors[0][i].b;
    185. }else{
    186. tmpVec=defaultColor;
    187. }
    188. tmp.color=tmpVec;
    189.  
    190. //color
    191. if(mesh->mTextureCoords[0])
    192. {
    193. tmpVec.x=mesh->mTextureCoords[0][i].x;
    194. tmpVec.y=mesh->mTextureCoords[0][i].y;
    195. }else{
    196. tmpVec.x=tmpVec.y=tmpVec.z=0.0;
    197. }
    198. tmp.U=tmpVec.x;
    199. tmp.V=tmpVec.y;
    200. data.push_back(tmp);
    201. }
    202.  
    203. for( unsigned int i=0;i<mesh->mNumFaces;i++)
    204. {
    205. aiFace face=mesh->mFaces[i];
    206. for( unsigned int j=0;j<face.mNumIndices;j++) //0..2
    207. {
    208. indices.push_back(face.mIndices[j]);
    209. }
    210. }
    211.  
    212.  
    213. for( unsigned int i=0;i<mat->GetTextureCount(aiTextureType_DIFFUSE);i++)
    214. {
    215. aiString str;
    216. mat->GetTexture(aiTextureType_DIFFUSE,i,&str);
    217. textureData tmp;
    218. tmp.id=loadTexture(str.C_Str());
    219. tmp.type=0;
    220. textures.push_back(tmp);
    221. }
    222. //meshes.push_back( new ::mesh(&data,&indices,&textures) );
    223. meshes.push_back( ::mesh(&data,&indices,&textures) );
    224. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. unsigned int meshLoader::loadTexture(const char* filename)
    2. {
    3. unsigned int num = 0;
    4. // glGenTextures(1,&num);
    5. // SDL_Surface* img=IMG_Load(filename);
    6. // if(img==NULL)
    7. // {
    8. // //std::cout << "img was not loaded" << std::endl;
    9. // return -1;
    10. // }
    11. // SDL_PixelFormat form={NULL,32,4,0,0,0,0,0,0,0,0,0xff000000,0x00ff0000,0x0000ff00,0x000000ff,0,255};
    12. // SDL_Surface* img2=SDL_ConvertSurface(img,&form,SDL_SWSURFACE);
    13. // if(img2==NULL)
    14. // {
    15. // //std::cout << "img2 was not loaded" << std::endl;
    16. // return -1;
    17. // }
    18. // glBindTexture(GL_TEXTURE_2D,num);
    19.  
    20. // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    21. // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    22. // glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,img2->w,img2->h,0,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8,img2->pixels);
    23. // SDL_FreeSurface(img);
    24. // SDL_FreeSurface(img2);
    25. return num;
    26. }
    27.  
    28.  
    29. meshLoader::meshLoader(const char* filename)
    30. {
    31. Assimp::Importer importer;
    32. const aiScene* scene = importer.ReadFile( filename, aiProcess_GenSmoothNormals | aiProcess_Triangulate | aiProcess_CalcTangentSpace | aiProcess_FlipUVs );
    33. if(scene->mFlags==AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
    34. {
    35. std::cout << "The file wasn't successfuly opened " << filename << std::endl;
    36. return;
    37. }
    38.  
    39. recursiveProcess(scene->mRootNode,scene);
    40. }
    41.  
    42. meshLoader::~meshLoader()
    43. {
    44. //for( unsigned int i=0;i<meshes.size();i++)
    45. //delete meshes[i];
    46. }
    47.  
    48. void meshLoader::draw(unsigned int programId)
    49. {
    50. size_t size = meshes.size();
    51.  
    52. for( unsigned int i = 0;i < meshes.size(); ++i )
    53. meshes[i].draw( programId );
    54. }
    55.  
    56. //std::vector<mesh*>& meshLoader::getMeshes()
    57. //{
    58. // return meshes;
    59. //}
    60.  
    61. meshLoader* scene;
    62.  
    63. Scene::Scene( QWidget *parent ) :
    64. QGLWidget( parent )/*,
    65.   m_objId( 0 ),
    66.   m_angle( 0 )*/
    67. {
    68. makeCurrent();
    69. globalGLFunctions = new QOpenGLFunctions_2_1;
    70.  
    71. globalGLFunctions->initializeOpenGLFunctions();
    72.  
    73.  
    74. // connect( &m_timer, SIGNAL( timeout( ) ),
    75. // this, SLOT( slotUpdate( ) ) );
    76. // m_timer.start( 50 );
    77. }
    78.  
    79. Scene::~Scene()
    80. {
    81. globalGLFunctions->glDetachShader( m_program, m_vs );
    82. globalGLFunctions->glDetachShader( m_program, m_fs );
    83. globalGLFunctions->glDeleteShader( m_vs );
    84. globalGLFunctions->glDeleteShader( m_fs );
    85. globalGLFunctions->glDeleteProgram( m_program );
    86. }
    87.  
    88. //void Scene::slotUpdate( )
    89. //{
    90. // ++m_angle;
    91. // if ( m_angle >= 360 )
    92. // {
    93. // m_angle = 0;
    94. // }
    95. // updateGL( );
    96. //}
    97.  
    98. void Scene::slotLoadObject( const QString &fileName )
    99. {
    100. scene = new meshLoader( fileName.toStdString( ).c_str( ) );
    101. }
    102.  
    103. void Scene::initializeGL( )
    104. {
    105. glClearColor(0,0,0,1);
    106. glMatrixMode(GL_PROJECTION);
    107. {
    108. glLoadIdentity();
    109. gluPerspective(50,640.0/480.0,1,1000);
    110. }
    111. glMatrixMode(GL_MODELVIEW);
    112. glEnable(GL_DEPTH_TEST);
    113.  
    114. // Load Shaders
    115. initShader( ":/vshader.glsl", ":/fshader.glsl" );
    116.  
    117. // Remove comment for to enable lighting
    118. // glEnable( GL_LIGHTING ); // we enable lighting, to make the 3D object to 3D
    119. // glEnable( GL_LIGHT0 );
    120. // float col[] = { 1.0, 1.0, 1.0, 1.0 }; //light color is white
    121. // glLightfv( GL_LIGHT0, GL_DIFFUSE, col );
    122.  
    123. // Remove comment for to enable fog
    124. // glEnable( GL_FOG ); // we enable fog
    125. // glFogi( GL_FOG_MODE, GL_LINEAR );
    126. // glFogf( GL_FOG_START, 1.0 );
    127. // glFogf( GL_FOG_END, 5.0 );
    128. // float fogColor[] = { 0.5, 0.5, 0.5, 1.0 };
    129. // glFogfv( GL_FOG_COLOR, fogColor );
    130. }
    131.  
    132. void Scene::paintGL( )
    133. {
    134. glLoadIdentity();
    135. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    136. //glRotatef(angle,0.0,1.0,0.0);
    137. //globalGLFunctions->glUniform3f( globalGLFunctions->glGetUniformLocation(m_program,"lightPos"),0,1,2);
    138. //glUniform3f(glGetUniformLocation(m_program,"cameraPosition"),cam.getLocation().x,cam.getLocation().y,cam.getLocation().z);
    139. glTranslatef( 0.0, 0.0, -5.0 );
    140. scene->draw( m_program );
    141.  
    142. // float pos[] = { 0.0, 0.0, 5.0, 1.0 }; //set the position
    143. // glLightfv( GL_LIGHT0, GL_POSITION, pos );
    144. // glTranslatef( 0.0, 0.0, -5.0 );
    145. // glRotatef( m_angle, 1.0, 1.0, 1.0 );
    146. // if ( m_objId != 0 ) {
    147. // glCallList( m_objId ); //draw the 3D mesh
    148. // }
    149. }
    150.  
    151. void Scene::resizeGL( int w, int h )
    152. {
    153. // Prevent a divide by zero
    154. if ( h == 0 )
    155. h = 1;
    156.  
    157. // Set Viewport to window dimensions
    158. glViewport( 0, 0, w, h );
    159.  
    160. // Reset coordinate system
    161. glMatrixMode( GL_PROJECTION );
    162. glLoadIdentity( );
    163.  
    164. // Produce the perspective projection
    165. gluPerspective( 45, 640.0 / 480.0, 1.0, 500.0 );
    166.  
    167. glMatrixMode( GL_MODELVIEW );
    168. glLoadIdentity( );
    169. }
    170.  
    171. void Scene::initShader( const QString &vname, const QString &fname )
    172. {
    173. // Create vertex shader
    174. std::string source;
    175. loadFile( vname, source );
    176. m_vs = loadShader( source, GL_VERTEX_SHADER );
    177.  
    178. // Create fragment shader
    179. source = "";
    180. loadFile( fname, source );
    181. m_fs = loadShader( source, GL_FRAGMENT_SHADER );
    182.  
    183. // Create a program
    184. m_program = globalGLFunctions->glCreateProgram();
    185. globalGLFunctions->glAttachShader( m_program, m_vs );
    186. globalGLFunctions->glAttachShader( m_program, m_fs );
    187.  
    188. globalGLFunctions->glLinkProgram( m_program );
    189. globalGLFunctions->glUseProgram( m_program );
    190. }
    191.  
    192. void Scene::loadFile( const QString &fileName, std::string &str )
    193. {
    194. QFile in( fileName );
    195. if ( !in.open( QIODevice::ReadOnly ) ) {
    196. std::cerr << "The file " << fileName.toStdString() << " cannot be opened.\n";
    197. return;
    198. }
    199.  
    200. while ( !in.atEnd() ) {
    201. QByteArray data = in.readLine();
    202. QString qstr( data );
    203. str += qstr.toStdString();
    204. }
    205. }
    206.  
    207. unsigned int Scene::loadShader( std::string &source, unsigned int mode )
    208. {
    209. unsigned int id = 0;
    210. id = globalGLFunctions->glCreateShader( mode );
    211.  
    212. const char *csource = source.c_str();
    213. globalGLFunctions->glShaderSource( id, 1, &csource, NULL );
    214. globalGLFunctions->glCompileShader( id );
    215. char error[1000];
    216. globalGLFunctions->glGetShaderInfoLog( id, 1000, NULL, error );
    217. std::cout << error;
    218.  
    219. return id;
    220. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    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

    So, have you checked the instance like I suggested?

    Cheers,
    _

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

    8Observer8 (4th December 2014)

  8. #6
    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

    Quote Originally Posted by anda_skoa View Post
    So, have you checked the instance like I suggested?

    Cheers,
    _
    Thank you very much! Yes, I checked the instance and I found the mistake! I called the method draw() when the instance of "meshLoader" object was not created
    Qt Code:
    1. meshLoader* scene;
    2.  
    3. //...
    4.  
    5. void Scene::slotLoadObject( const QString &fileName )
    6. {
    7. scene = new meshLoader( fileName.toStdString( ).c_str( ) );
    8. }
    To copy to clipboard, switch view to plain text mode 

    I solved it like this:
    Qt Code:
    1. void Scene::slotLoadObject( const QString &fileName )
    2. {
    3. isLoaded = true;
    4. scene = new meshLoader( fileName.toStdString( ).c_str( ) );
    5. }
    6.  
    7. // ...
    8.  
    9. void Scene::paintGL( )
    10. {
    11. // ...
    12.  
    13. if ( isLoaded )
    14. scene->draw( m_program );
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by 8Observer8; 4th December 2014 at 14:19.

  9. #7
    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

    If you properly initialize the pointer to 0, you can check the variable itself instead of needing the boolean flag.

    Cheers,
    _

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

    8Observer8 (5th December 2014)

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.