Error -1073741819 o (C0000005)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Error -1073741819 o (C0000005)

  1. #1
    Join Date
    Apr 2011
    Posts
    4

    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);

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,554

    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:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  3. #3
    Join Date
    Apr 2011
    Posts
    4

    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.

  4. #4
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,060

    Re: Error -1073741819 o (C0000005)

    [ Moved thread ]
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    My likes on StumbleUpon
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  5. #5
    Join Date
    Apr 1999
    Posts
    27,446

    Re: Error -1073741819 o (C0000005)

    Quote Originally Posted by Cucus View Post
    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 02:02 PM.

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,595

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center