What would cause fstream to read in crazy stuff? It works the first 80 or so times fails eventually, which is unacceptable.
My frames number will read in as some huge negative number and temp in all cases will be nothing so I end up with the root_path and that is it. Would using load_file.bad() be an option here? What could be causing my issue with reading a small text file?
Describe your data.
Also, what do you mean that it "works for the first 80 or so"? The first 80 what? Independent runs of the program on the same data? Iterations of a loop in a single run?
Well this is a monster class that loads monster data from a file the file contains simple data paths for the animations and such. I can spawn 80 monsters or so shoot emm up and whatnot, but then all of a sudden fstream doesnt populate temp and my frames count which causes the program to crash atm.
this is the file:
17 32 5 2
28 32 8 1
48 32 15 1
This is my constructor at the moment:
Monster::Monster(string filename,Resource_Manager *nrm)
rm = nrm;
Draw_Hit_Zones = true;
Draw_Health_Bar = true;
last_zone_hit = -1;
Dieing = false;
Time_Of_Death = 0;
cur_state = 0;
MAGIC = NULL;
delay = 100;
cur_frame = 0;
dr = 0;
r = 0;
Move_Speed = 10;
timer = clock();
Max_Hit_Points = 50;
Cur_Hit_Points = Max_Hit_Points;
//end class initalizations
string root_path = filename.substr(0,filename.find_last_of("/\\")+1); // /gfx/Spider/
magic_number = (int)ceil(sqrt(rm->Get_Sprite(W_ANI,0)->w*rm->Get_Sprite(W_ANI,0)->w + rm->Get_Sprite(W_ANI,0)->h*rm->Get_Sprite(W_ANI,0)->h));
Hit_Zones = new C_Circ*[num_col];
multipliers = new int[num_col];
for(int lcv = 0;lcv < num_col;lcv++)
Hit_Zones[lcv] = new C_Circ(cx+(magic_number-rm->Get_Sprite(W_ANI,0)->w)/2,cy+(magic_number-rm->Get_Sprite(W_ANI,0)->h)/2,cr);
Master_Hit_Zone = new C_Rect(x - (rm->Get_Sprite(W_ANI,0)->w/2),y - (rm->Get_Sprite(W_ANI,0)->h/2),rm->Get_Sprite(W_ANI,0)->w,rm->Get_Sprite(W_ANI,0)->h);
So you can read about 80 separate "monster" files but after that they start screwing up? It would seem that the problem is not in the Monster ctor then.
How are you maintaining the "list" of monsters?
BTW, dieing is spelled dying (if you mean death as opposed to dice or machine stamping/cutting).
Since when does grammar effect code? Same file multiple times, but only one load of the images.
Are you actually mad that I pointed out a spelling error? Most people would like their variables, etc, to be spelled correctly. Then again, most people get upset when you point out spelling errors. It's a bad habit of mine, I guess.
At any rate, you haven't explained/showed how you're handling the list of monsters. Clearly there's nothing wrong with the code you posted. So the error lies elsewhere.
I use a vector the problem is in that code since a data dump shows only the root paths instead of the full paths. I also get some huge negative number for my num frames. So ifstream is failing me somehow. Generally I spawn 25 monsters at a time kill them redo and eventually the loading code fails
Since you want to see how I handle the list of monsters....
Nothing interesting there. It is with the values being read from the fstream not with anything else. The values are FUBAR not how I add things to my vector. If you have no clue which it is obvious you don't bugger off let someone with a few more brain cells help.
vector <Monster *>my_monsters;
New_Monster = new Monster("gfx/Spider/spider.txt",res_m);
New_Monster->Set_XY(player->Get_X_Pos() + 100,player->Get_Y_Pos() + 100);
Calm down charlie brown. Don't insult someone who's trying to help you about their intelligence when it's obvious since you can't figure it out, you're no more intelligent than they are. I hate kids like that.
Ok so I added code to check the fstream object....
I get the output of:
if(!load_file.good())allegro_message("LOAD FILE IS BAD! FLAGS SET\n EOF: %i \n BAD: %i \n FAIL: %i", load_file.eof(),load_file.bad(),load_file.fail());
LOAD FILE IS BAD! FLAGS SET
What does this mean what is happening?
It means that, at some point, it failed to read some value. Maybe one of your data files is corrupted? For example, if it fails to parse an int, it will stop reading, set the fail flag, and not do anything else until you clear the flag. Which means that if you try to read into another variable it won't change that variable, and if that variable was uninitialized before the read attempt, it will be some random value. This is most likely the source of that "huge negative value" you're seeing.
+1 internets for using Allegro. I love that library.
The shear fact that it sets the fail bit on opening a file though? I mean I am using the same file over and over it's not like I am switching between files(not yet at least, no animations!)
@Rod, I was referring to the point of the debugger points me here the allegro.cc forums point me there, the fail bit points me there and according to this guy it is in my vector management?
Problem is that there are too many open files somehow as per my question on stackoverflow.com; Oddly enough I close the file every time I am not sure why I run out of descriptors.