Menu

Access Violation on eVC++4

John Idol
2008-07-15
2013-05-20
  • John Idol

    John Idol - 2008-07-15

    Hi All,

    I am using tinyXML on eVC++4.
    Everything works fine but out of nowhere I have an Access Violation on a call to the ToElement() method of the TiXmlNode. Strange thing is that I am calling it before several times without any problem.

    my code:

    TiXmlNode* node = 0;
    TiXmlElement* modelElement = 0;
    TiXmlNode* rootNode = 0;

    rootNode = m_doc.RootElement();

    node = rootNode;
    testData.TagAValue = GetTagA(node);
    node = rootNode;
    testData.TagBValue = GetGetTagB(node);
    node = rootNode;
    testData.TagCValue = GetTagC(node);//<--Access violation in Here
    //...And so forth

    the GetTag functions are very similar and they look something like:

    CString GetTagC(TiXmlNode* node)
    {
            CString tempStr = _T("");
            TiXmlElement* modelElement = 0;

            node = node->FirstChild(C_TAG_LIST);
            node = node->FirstChild(C_TAG);
            modelElement = node->ToElement();//<--Access Violation on this LINE!!!
            for( modelElement; modelElement; modelElement=modelElement->NextSiblingElement())
            {
                    tempStr = modelElement->Attribute(META_NAME);
                    if (tempStr == MY_C_NAME_ATTRIBUTE)
                    {
                            tempStr = modelElement->Attribute(META_VALUE);
                            return tempStr;
                    }
            }
           
            return _T("");
    }

    I an doing the same things on each so why is it crashing on GetTagC?
    Any help/suggestion/clue would be higly appreciated!

    Thanks

     
    • John Idol

      John Idol - 2008-07-15

      I was looking for the wrong TAG:

      node = node->FirstChild(C_TAG);

      and then accessing it without checking the result.

       

Log in to post a comment.