Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Having problems with STL vectors.

This topic is 5461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Basically what I have done is that I''ve created a class called C3DObject. My Model class store a vector of C3DObjects. Now this all seems to work fine, but when I try and do something like this... class C3DObject { public: int numFaces; }; vector pObjects; // Fill in the vector // This is where problem arises. pObjects[].numFaces the compiler doesn''t know what''s going on. Anyone got any ideas? I''ve been trying to fix this for the last 4 hours, and still have no idea what the problem is.

Share this post

Link to post
Share on other sites
put it in [ source ] and [ /source ] tags (with the brackets, without the spaces).

How appropriate. You fight like a cow.

Share this post

Link to post
Share on other sites
Take a look at the code tell me if you see anything wrong


#include <stdio.h>
#include <vector>
#include <fstream.h>
#include <math.h>
#include "3DMath.h"
#include "main.h"

#ifndef _3DMODEL_H
#define _3DMODEL_H

using namespace std;

#define VERTEX 0
#define TEXTURE 1
#define NORMAL 2

struct tFace {
vector<int> vertIndex;
vector<int> normIndex;

class C3DObject {

int numVerts;
int numFaces;
int numNorms;
char strName[255];
CVector3 *pVerts;
CVector3 *pNormals;
tFace *pFaces;


class C3DModel {

int LoadOBJModel(char *strFilename);
int CreateDisplayList();
// DrawObject(...)

void DrawModel();
// DestroyModel(...)

FILE* pFilePointer;
int numObjects;
bool b_justReadAFace, b_fileContainsNormals, b_hasDisplayList;
GLuint displayList;
vector<C3DObject> pObjects;

int LoadOBJFileData();
int LoadOBJVertexData();
int ReadOBJVertex();
int ReadOBJNormal();
int LoadOBJFaceData();
int FillInObjectData();
int ComputeNormals();



3DModel.cpp where I''m having problems

int C3DModel::CreateDisplayList()
if(numObjects == 0) // Do we have any objects to create a display list with?

return 1;

displayList = glGenLists(1);
glNewList(displayList, GL_COMPILE);
glColor3f(1.0f, 0.0f, 0.0f);

for(int i=0;i<pObjects.size();i++) {
for(int j=0;j<pObjects[i].numFaces;j++) {

for(int k=0;k<pObjects[i].pFaces[j].vertIndex.size();k++) {
// ############# BLOWS UP RIGHT HERE ###################

// When i=1 it blows up. Only blows up for normals

// If I comment out normals it works fine.

if(b_fileContainsNormals) {


b_hasDisplayList = true;
return 1;

Share this post

Link to post
Share on other sites
it could be possible that the variables you use to keep count of the faces and stuff do not coincide.

insteady of using separate variables, try using the vector''s size().


vector m_vList;


cout << "size = " << m_vList.size() << endl;

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!