Thought I'd post an update for anyone else who is/was having a problem with GetLine (I hate when I find search results and the person didn't reply back a solution :P ).
Ok so basically I rewrote the routine and tightened it all up quite a bit.
Originally indicies was declared as this:
short indicies[15000]
so I made it [30000], that seemed to help, so I made it [90000] which was more than enough but it didn't seem to make much difference (And I hated to see such an enormous number for an array especially if half of it would be empty/wasted elements), but because it got better when I made it to [30000] I figured it HAD to be some issue with what you mentioned buffer overflow or some form of memory corruption. So I took a page out of my MaterialManager book. Here's what I did:
declared in the class: short *indicies;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
indicies = new short[FaceCount * 3];
for (i = 0; i < (FaceCount - 1) * 3; i+=3)
{
getline(ModelFileIn, LineBuffer);
SeperatorPosition1 = LineBuffer.find(":", 0); // ex: 0
SeperatorPosition1 = LineBuffer.find(":", SeperatorPosition1 + 1); //A:
SeperatorPosition2 = LineBuffer.find(":", SeperatorPosition1 + 1); //B:
SeperatorPosition3 = LineBuffer.find(":", SeperatorPosition2 + 1); //C:
SeperatorPosition4 = LineBuffer.find("AB", SeperatorPosition3 + 1);
TempString2 = LineBuffer.substr(SeperatorPosition1 + 1, SeperatorPosition2 - (SeperatorPosition1 + 3));
TempString2 = trim(TempString2);
indicies[i] = boost::lexical_cast<short>(TempString2);
NumOfIndexes += 1;
TempString2 = LineBuffer.substr(SeperatorPosition2 + 1, SeperatorPosition3 - (SeperatorPosition2 + 3));
TempString2 = trim(TempString2);
indicies[i + 1] = boost::lexical_cast<short>(TempString2);
NumOfIndexes += 1;
TempString2 = LineBuffer.substr(SeperatorPosition3 + 1, SeperatorPosition4 - (SeperatorPosition3 + 2));
TempString2 = trim(TempString2);
indicies[i + 2] = boost::lexical_cast<short>(TempString2);
NumOfIndexes += 1;
TempString2 = "";
};
|
In my Material Manager, I basically wrote a function call AddMaterialSlot, and all it does is add's a slot to a dynamic array with data-preservation, read about it in a pdf somewhere on the net (Can't recall the url). I started using this for the indicies, but because FaceCount is not a number that increases through a loop I couldn't implement a AddSlot type of technique at the begining of each for loop. I could have potentially done something like that for the For Loops i variable but then it would get really complicated adjusting for 3 elements per index plus whether elements are 0 indexed or not 0 indexed. blah blah so forth and so on lol
Basically the solution boiled down to:
1) I made the indicies dynamically set, this has the benefit of only making each model instance use only up to the amount of minimum memory required.
2) Instead of using TempString2 for each return of the boost lexical cast, I just set it right to indicies,
3) The For Loop needed to be changed to (FaceCount - 1) * 3. I'm not really sure why. FaceCount, I beleive, is 1 indexed as it comes directly from the model file. Either way -1'ing it seemed to help. Without -1'ing it, I was getting boost bad_cast errors which tipped me off that it was casting on data the routine wasn't designed for meaning it was at a different spot in the file than was anticipated.
Probably a few other changes, but it's fixed, yay! Hope this helps others!