I’m getting this error, the reason I just can’t figure out. Is it type issues?
the error is on the line:
“size = objmesh->n_objvertexdata * sizeof(vec3) * sizeof(vec3);”
Not sure what it is, been fiddling with it. Help?
objmesh = &objmesh[0];
unsigned char *vertex_array = NULL,
*vertex_start = NULL;
unsigned int i = 0, index = 0, stride = 0, size = 0;
size = objmesh->n_objvertexdata * sizeof(vec3) * sizeof(vec3); //this lines gives error
vertex_array = (unsigned char *) malloc(size);
vertex_start = vertex_array;
while (i != objmesh->n_objvertexdata) {
index = objmesh->objvertexdata[i].vertex_index;
memcpy(vertex_array, &obj->indexed_vertex[index], sizeof(vec3));
vertex_array += sizeof(vec3);
memcpy(vertex_array, &obj->indexed_normal[index], sizeof(vec3));
vertex_array += sizeof(vec3);
++i;
The crash is probably because objmesh is an invalid pointer (either NULL or just dangling pointer). And when you’re accessing memory relative to the invalid pointer you’ll get the crash.
Or here is another reason. As I understand objmesh is some container that holds some data and it’s size. When you’re doing this
objmesh is no longer container, it is data that it holds. So you should use another variable for assignment.