this is a c++ question.
I'm working on an OpenGL project. wrote a simple OBJ loader. I have a class called Mesh. By getting an object pointer called monkey
Mesh* monkey;
and calling function:
load_obj("Monkey.obj", monkey);
I want to read from file and put it in monkey vertices. but when running it gives me unhandled exception:read violation when want to pushback to vector at:
mesh->vertices.push_back(v);
I tested a local vector dummy but it successfully pushedback. I don't know why it can't push to the object pointers vector?
here is the mesh header
include[...]
using namespace std;
class Mesh {
private:
GLuint vbo_vertices, vbo_normals, ibo_elements;
public:
vector <glm::vec4> vertices;
vector <glm::vec3> normals;
vector <GLushort> elements;
glm::mat4 object2world;
Mesh() : vertices(1), normals(1), elements(3), object2world(glm::mat4(1)) {}
~Mesh(void){} ;
void Mesh::draw(void) ;
};
and this is the obj-loader.cpp relative part
void load_obj(const char* filename, Mesh* mesh) {
ifstream in(filename, ios::in);
if (!in) { cerr << "Cannot open " << filename << endl; exit(1); }
vector<int> nb_seen;
vector<glm::vec4> dummy;
string line;
while (getline(in, line)) {
if (line.substr(0,2) == "v ") {
istringstream s(line.substr(2));
glm::vec4 v; s >> v.x; s >> v.y; s >> v.z; v.w = 1.0;
dummy.push_back(v);
mesh->vertices.push_back(v);
}
any help would be appreciated! your confused friend!