-
April 19th, 2011, 09:42 AM
#1
Error -1073741819 o (C0000005)
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
Code:
#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:
Code:
#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":
Code:
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:
Code:
void ProcessFile(std::vector<Joint> *joints, TiXmlDocument* pParent);
-
April 19th, 2011, 10:06 AM
#2
Re: Error -1073741819 o (C0000005)
How do you call your:
bool xml::loadData(const char* fileName, std::vector<Joint> *joints)?
Most likely, "joints" is not initialized.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
April 19th, 2011, 11:53 AM
#3
Re: Error -1073741819 o (C0000005)
Joints is initialized in another class, here's de header
Code:
#ifndef ROBOT_H
#define ROBOT_H
#include "vector"
#include "joint.h"
class Robot
{
public:
Robot();
void loadData(const char* fileName);
public:
std::vector<Joint> joints;
};
#endif // ROBOT_H
But the problem is not here, the problem stills on the function Joint::addVertex(Vertex &v) (checked with qDebug()) and I don't know why.
-
April 19th, 2011, 12:00 PM
#4
Re: Error -1073741819 o (C0000005)
-
April 19th, 2011, 12:20 PM
#5
Re: Error -1073741819 o (C0000005)
Originally Posted by Cucus
Joints is initialized in another class,
How are we sure of this?
But the problem is not here, the problem stills on the function Joint::addVertex(Vertex &v) (checked with qDebug()) and I don't know why.
Your Joint class is not safely copyable, since it contains a pointer member. You are adding Joint objects by value into a vector, and the vector will make copies.
Code:
std::vector<Joint> *nextJoint;
How do you handle this member when copies are made?
The bottom line is this -- your program is doing pointer manipulations -- if you make one mistake anywhere in your program wth the usage of pointers, this mistake can manifest itself in other parts of your program that may have nothing to do with pointers. Working with pointers isn't a freebie -- you must be aware, at all times, what you're doing and the consequences of such.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; April 19th, 2011 at 01:02 PM.
-
April 19th, 2011, 12:25 PM
#6
Re: Error -1073741819 o (C0000005)
The error message indicates an illegal memory access, usually caused by the use on an invalid pointer.
Because the vector class stores copies of the elements you add to it, IMO another candidate culprit is a bug in the Vertex copy constructor and/or copy assignment operator (or simply the absence of just that).
Just a qualified guess...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|