bool CLevelReader::LevelParser()
{
TiXmlDocument doc;
//attempt to load doc
if(!doc.LoadFile("Pegs.xml"))
{
return false;
}
// Access the root element ("peg_list"_ in the doc
TiXmlElement* pRoot = doc.RootElement();
if(pRoot == nullptr)
return false;
// Load each peg data from the document
// and store the vector
m_vLoadedLevel.clear();
TiXmlElement* pPeg = pRoot->FirstChildElement("peg_info");
// while there is still info in the xml doc
while(pPeg != nullptr)
{
// Read the peg info from this node
Peg info = { };
//Read the type
double buffer;
if(pPeg->Attribute("type", &buffer) != nullptr)
{
info.m_nType = (int)buffer;
}
if(pPeg->Attribute("width", &buffer) != nullptr)
{
info.m_nWidth = (int)buffer;
}
if(pPeg->Attribute("height", &buffer) != nullptr)
{
info.m_nHeight = (int)buffer;
}
if(pPeg->Attribute("x", &buffer) != nullptr)
{
info.m_fX = (float)buffer;
}
if(pPeg->Attribute("y", &buffer) != nullptr)
{
info.m_fY = (float)buffer;
}
if(pPeg->Attribute("velX", &buffer) != nullptr)
{
info.m_fVelocityX = (float)buffer;
}
if(pPeg->Attribute("velY", &buffer) != nullptr)
{
info.m_fVelocityY = (float)buffer;
}
if(pPeg->Attribute("imageID", &buffer) != nullptr)
{
info.m_nImageID = (int)buffer;
}
// store the peg info
m_vLoadedLevel.push_back(&info);
//move to the next pegin the list
pPeg = pPeg->NextSiblingElement("peg_info");
}
return true;
}
The above code works fine and everything is filled out at this point.
Now in main...
CLevelReader* level = new CLevelReader();
level->SaveLevel();
level->LevelParser();
vector<Peg*> temp;
//memcpy(temp[0], level->GetLevel()[0], sizeof(Peg));
for(int i = 0; i < level->GetVector().size(); ++i)
{
temp[i] = level->GetVector()[i];
}
By the time i reach the loop GetVector[i] is garbage values...
Below are some more code snipets
// in CLevelReader.h
std::vector<Peg*> GetVector(void){return m_vLoadedLevel;}
struct Peg
{
int m_nType;
int m_nWidth;
int m_nHeight;
float m_fX;
float m_fY;
float m_fVelocityX;
float m_fVelocityY;
int m_nImageID;
};
I have tried almost everything i could think of, but i don't really know if i am using pointers correctly, how to really fix the problem. Hence where you guys come in!

New Topic/Question
Reply



MultiQuote







|