S
Skywise
This function loads info from a binary data file, then loads objects
(currently 23 in the test file). Here is the loading function:
bool UnitDefLoad(char* sFile)
{
UnitDefCleanList(false); // tested. This works.
int iUnitCount = 0;
UNIT_DEF uData; // Theses objects are read from file
ifstream fin(sFile,ios::binary);
if (!fin)
{
return false;
} // end if
else
{
fin.read((char*) &Unit_Def_Node::Arthur, sizeof
(Unit_Def_Node::Arthur));
fin.read((char*) &Unit_Def_Node::iMonth, sizeof
(Unit_Def_Node::iMonth));
fin.read((char*) &Unit_Def_Node::iDay, sizeof
(Unit_Def_Node::iDay));
fin.read((char*) &Unit_Def_Node::iYear, sizeof
(Unit_Def_Node::iYear));
fin.read((char*) &Unit_Def_Node:escription, sizeof
(Unit_Def_Node:escription));
fin.read((char*) &Unit_Def_Node::iVersion, sizeof
(Unit_Def_Node::iVersion));
fin.read((char*) &Unit_Def_Node::iBuild, sizeof
(Unit_Def_Node::iBuild));
fin.read((char*) &iUnitCount, sizeof (iUnitCount));
for (int iCount = 1; iCount < iUnitCount; iCount++)
{
fin.read((char*) &uData, sizeof (uData));
UnitDefADD(uData);
cout << "Number of Unit_Def_Nodes: " << iUnitsDefined << "\n";
}; // end for
};
fin.close();
return true;
};
I believe the problem is the
fin.read((char*) &uData, sizeof (uData));
in the for loop. I have 23 UNIT_DEF objects saved in the file. After
the 23rd object is loaded, it exits the loop and crashes... if I
comment out the above line, the program works fine. Is there
something wrong with my syntax?
(currently 23 in the test file). Here is the loading function:
bool UnitDefLoad(char* sFile)
{
UnitDefCleanList(false); // tested. This works.
int iUnitCount = 0;
UNIT_DEF uData; // Theses objects are read from file
ifstream fin(sFile,ios::binary);
if (!fin)
{
return false;
} // end if
else
{
fin.read((char*) &Unit_Def_Node::Arthur, sizeof
(Unit_Def_Node::Arthur));
fin.read((char*) &Unit_Def_Node::iMonth, sizeof
(Unit_Def_Node::iMonth));
fin.read((char*) &Unit_Def_Node::iDay, sizeof
(Unit_Def_Node::iDay));
fin.read((char*) &Unit_Def_Node::iYear, sizeof
(Unit_Def_Node::iYear));
fin.read((char*) &Unit_Def_Node:escription, sizeof
(Unit_Def_Node:escription));
fin.read((char*) &Unit_Def_Node::iVersion, sizeof
(Unit_Def_Node::iVersion));
fin.read((char*) &Unit_Def_Node::iBuild, sizeof
(Unit_Def_Node::iBuild));
fin.read((char*) &iUnitCount, sizeof (iUnitCount));
for (int iCount = 1; iCount < iUnitCount; iCount++)
{
fin.read((char*) &uData, sizeof (uData));
UnitDefADD(uData);
cout << "Number of Unit_Def_Nodes: " << iUnitsDefined << "\n";
}; // end for
};
fin.close();
return true;
};
I believe the problem is the
fin.read((char*) &uData, sizeof (uData));
in the for loop. I have 23 UNIT_DEF objects saved in the file. After
the 23rd object is loaded, it exits the loop and crashes... if I
comment out the above line, the program works fine. Is there
something wrong with my syntax?