Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion `_attributePool.CurrentAllocs() == _attributePool.Untracked()' failed #555

Open
terminaldweller opened this issue May 23, 2017 · 7 comments

Comments

@terminaldweller
Copy link

I think the assert gets triggered wrongly on inheritance. I'll explain more with code:
first suppose we have:
in the header:
BaseClass
[
public:
XMLReportBase();
~XMLReportBase();

void CreateReport(void);

virtual void AddNode(void) = 0;

void SaveReport(const char*);

protected:
XMLDocument Doc;
XMLElement* RootPointer;

}

in the source file:
BaseClass
{
XMLReportBase::XMLReportBase()
{
RootPointer = Doc.NewElement("mutagen:Report");
RootPointer->SetAttribute("xmlns:mutator", "http://www.w3.org/2001/XMLSchema");
}

XMLReportBase::~XMLReportBase()
{
Doc.InsertEndChild(RootPointer);
}

void XMLReportBase::CreateReport()
{
Doc.InsertFirstChild(RootPointer);
}

void XMLReportBase::SaveReport(const char* __filename)
{
Doc.InsertEndChild(RootPointer);

XMLError XMLErrorResult = Doc.SaveFile(__filename);

if (XMLErrorResult != XML_SUCCESS)
{
  std::cerr << "could not write xml misra report.\n";
}

}
}

now if:
B : BaseClass
{
/ctor,dtor,implementation of the pure virtual function, .../
}

this will trigger the assert. If I just move everything into B without inheritance then the assert won't get triggered.
Am I doing something wrong or the assert is being raised incorrectly?
BTW, thank you for tinyxml2. it makes life easier. :)

@Dmitry-Me
Copy link
Contributor

This is most likely because of destructor of XMLReportBase not being virtual. How exactly is the object created and deleted where you observe the problem? Do you have a minimal source which shows the problem with the above two classes? Which compiler (and which version) do you use?

@terminaldweller
Copy link
Author

I did try the virtual destructor, it still keeps raising the same assert.
actually the above code was kinda a minimal source version of the original code. The original piece is on my repo but I guess looking at it there is gonna take more time than necessary. or i can just cut the relevant pieces and put them up here.
I'm using clang, trunk 301395. I build my own.
Regarding the way it's built and destructed, it's nothing fancy.
I just call the constructor for B, call XMLReportBase::CreateReport and XMLReportBase::SaveReport, the assert fails even with just creating a doc, and adding a root node and then just saving it:
void myclass::myfunc(void)
{
B b(myvar1);
b.CreateReport();
b.SaveReport();
}

then I just call mycall::myfunc(). Also for the record, the XML document is just fine(I've looked at issue #129., At first I though the problem was that, but like I said I get the same assert with just adding one root node.

@Dmitry-Me
Copy link
Contributor

Does the same node get added multiple times into the DOM?

@terminaldweller
Copy link
Author

terminaldweller commented May 23, 2017 via email

@Dmitry-Me
Copy link
Contributor

What's inside

/ctor,dtor,implementation of the pure virtual function, .../

?

@terminaldweller
Copy link
Author

terminaldweller commented May 26, 2017

ctor:

RootPointer = Doc.NewElement("mutagen:Report");
RootPointer->SetAttribute("xmlns:mutator", "http://www.w3.org/2001/XMLSchema");

dtor:

Doc.InsertEndChild(RootPointer);

other stuff:
in the header:

virtual void AddNode(void) = 0;

in the source:
DoomedStrains is vector<vector>

virtual void AddNode(void)
    {
      XMLElement* MGene = Doc.NewElement("DoomedStrains");

      for (auto &iter : DoomedStrains)
      {
        XMLElement* NodeDoomedStrain = Doc.NewElement("DoomedStrain");

        for (auto &iterer : iter)
        {
          XMLElement* Child = Doc.NewElement("Strain");
          Child->SetText(iterer.c_str());
          NodeDoomedStrain->InsertEndChild(Child);
        }
        
        MGene->InsertEndChild(NodeDoomedStrain);
      }

      RootPointer->InsertEndChild(MGene);
    }

@Dmitry-Me
Copy link
Contributor

There's good chance that for some reason you have XMLNode::InsertAfterChild() called with insertThis being equal to afterThis and that's the node other than the last one on that level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants