Error -1073741819 o (C0000005)
Apr 19, 2011 at 2:40pm UTC
Hi,
I'm trying to add "Vertex" elements to a vector. However, when I try to execute the program, I have an error: Error -1073741819 (or C0000005)
What does this error mean? Can you help me to resolve it? Thanks!
Here's the code
Function with the error in bold
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include "joint.h"
#include <QDebug>
Joint::Joint()
{}
void Joint::addVertex(Vertex &v)
{
vertexVector.push_back(v);
}
Vertex Joint::getVertex(int i)
{
return vertexVector[i];
}
int Joint::numberVertex()
{
return vertexVector.size();
}
void Joint::addJoint(Joint j)
{
nextJoint->push_back(j);
}
Header of the class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef JOINT_H
#define JOINT_H
#include "vector"
#include "vertex.h"
class Joint
{
public :
Joint();
void addVertex(Vertex &);
void addJoint(Joint);
Vertex getVertex(int );
int numberVertex();
private :
std::vector<Vertex> vertexVector;
std::vector<Joint> *nextJoint;
};
#endif // JOINT_H
The call to the function with the error from a class called "xml":
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
bool xml::loadData(const char * fileName, std::vector<Joint> *joints)
{
qDebug() << "Checkpoint 2" <<endl;
TiXmlDocument doc(fileName);
bool loadOkay = doc.LoadFile();
qDebug() << "Checkpoint 3" <<endl;
if (loadOkay)
{
printf("\n%s:\n" , fileName);
qDebug() << "Checkpoint 4" <<endl;
ProcessFile(joints, &doc ); // defined later in the tutorial
}
else
{
printf("Failed to load file \"%s\"\n" , fileName);
}
return loadOkay;
}
void xml::ProcessFile(std::vector<Joint> *joints, TiXmlDocument* pParent )
{
char * cstr, *word;
string line;
size_t found;
Vertex v;
ifstream file;
file.open ("C:/Users/Marcus/Desktop/C++/ABB_IRB1600_145-0.STL" );
if (file.is_open())
{
while ( file.good() )
{
getline(file,line);
found = line.find("vertex" );
if (found != 0 && found < 1000)
{
line.erase(0,16);
cstr = new char [line.size()+1];
strcpy (cstr, line.c_str());
word = strtok(cstr," " );
v.x = atof(word);
word = strtok(NULL," " );
v.y = atof(word);
word = strtok(NULL," " );
v.z = atof(word);
word = strtok(NULL," " );
//ERROR HERE!!!!
/**-|-|-|-|-|-|-|-|-|-|-|-|-|-**/
joints->front().addVertex(v);
/**-|-|-|-|-|-|-|-|-|-|-|-|-|-**/
}
}
}
file.close();
}
The function described before in xml.h:
void ProcessFile(std::vector<Joint> *joints, TiXmlDocument* pParent);
Last edited on Apr 19, 2011 at 2:41pm UTC
Apr 19, 2011 at 2:52pm UTC
Do you know how to use a debugger? It would be good to set a breakpoint and step through with a debugger to pinpoint the line causing the problem.
Apr 19, 2011 at 3:19pm UTC
1 2 3 4 5 6
v.x = atof(word);
word = strtok(NULL," " );
v.y = atof(word);
word = strtok(NULL," " );
v.z = atof(word);
word = strtok(NULL," " );
You're trying to tokenize NULL.
EDIT: Ahh, nevermind.
Last edited on Apr 19, 2011 at 3:23pm UTC
Apr 19, 2011 at 4:18pm UTC
I don't know how to use the debugger (I'm using Qt SDK -> QtCreator). However I know where's the problem, is in this function, where I do the push_back:
1 2 3 4
void Joint::addVertex(Vertex &v)
{
vertexVector.push_back(v);
}
I use some qDebug() to know where the program stop (qDebug() << is like "cout <<").
Topic archived. No new replies allowed.