Recently I found that if I press F5 in vs2008(run game in debug mode), every thing works right. However, when I run game directly(ctrl+F5) without debug mode, it crashes.
It turns out the string is empty after loading the imformation from xml..
here's the code:
Code: Select all
void tankFactory::build()
{
path path_body,path_turret,path_cannon,path_trackModelL,path_trackModelR;
//a lot of path type here
IFileSystem*fs=device->getFileSystem();
IXMLReader*xml=fs->createXMLReader(stringc("models/vehicle/ground/")+tType+"/modelInfo.xml");
while(xml&&xml->read())
{
switch(xml->getNodeType())
{
case EXN_ELEMENT:
stringc nodeName=xml->getNodeName();
if (nodeName.equals_ignore_case(L"attributes"))
{
IAttributes *attr=fs->createEmptyAttributes();
attr->read(xml,true);
path_body=attr->getAttributeAsString("body");
path_trackModelL=attr->getAttributeAsString("leftTrack");
path_trackModelR=attr->getAttributeAsString("rightTrack");
//same operation with other string
}
}
//load the model with path loaded above
mesh_body=smgr->getMesh(stringc("./models/vehicle/ground/")+tType+"/"+path_body);
mesh_trackL=smgr->getMesh(stringc("./models/vehicle/ground/")+tType+"/"+path_trackModelL);
mesh_trackR=smgr->getMesh(stringc("./models/vehicle/ground/")+tType+"/"+path_trackModelR);
mesh_turret=smgr->getMesh(stringc("./models/vehicle/ground/")+tType+"/"+path_turret);
//similiar operation
//.......other code
}
but when running directly(ctrl+F5,or open the .exe file in windows), the one of the path value would be empty after the information is loaded.
when game crashes, the path object's string array is empty while the variable "allocated" and "used" in the object is not 0.
(e.g path_body , the xml wirtes:"body.x";
by the time when I trying to load mesh,
it becomes: array="",allocated=6,used=6, the array is missing)
I heard that visual studio would automatically initialize the variable when debuging, but if you run your program in windows, you should initialize ot yourself..
So..What should I do?