Maybe seeing the issue would help you all a little:
https://ws.onehub.com/files/nzvrbj4s
Screen Shots:
https://ws.onehub.com/files/9rw3li12
https://ws.onehub.com/files/37ggbfio
This is the demo exe file.
WASD to move the player around
mouse to aim
mouse left click to fire
R to Reload
M to Create a monster (I have one spawn point in the game that spits out 5 monsters 3 alive at a time max on the spawn point)
I am loading monster data in from a file which contains the following:
Spider_Walk/
12
Spider_Attack/
1
Spider_Die/
9
3
17 32 5 2
28 32 8 1
48 32 15 1
I check the file every time I spawn a spider for the data of the hit zones and file paths for the animations. I do not reload the animations every time due to the resource manager class which prevents multiple animations from being double loaded. Currently I can spawn many many monsters, but then out of the blue ifstream sets the fail bit on me and I crash. I am trying to understand why my fail bit is being set.
My output is:
(1)LOAD FILE IS BAD! FLAGS SET
EOF: 0
BAD: 0
FAIL: 1
FILENAME.c_str(): gfx/Spider/Spider.txt
Any advice would be helpful at the moment I am thinking about making a monster info class and putting it in with the resource manager to only load monster data one time. I just fear this failure is the tip of the iceberg and something much bigger is lurking.
Smallest code chunk that would probably eventually reproduce the issue.
ifstream load_file;
load_file.open(filename.c_str());
if(!load_file.good())allegro_message("(1) LOAD FILE IS BAD! FLAGS SET\n EOF: %i \n BAD: %i \n FAIL: %i \n FILENAME.c_str(): %s", load_file.eof(), load_file.bad(), load_file.fail(), filename.c_str());
FULL CONSTRUCTOR CODE FOLLOWS:
Monster::Monster(string filename,Resource_Manager *nrm)
{
rm = nrm;
//Class initalizations
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
stringstream ss;
string root_path = filename.substr(0,filename.find_last_of("/\\")+1); // /gfx/Spider/
string load_image_path;
string load_mask_path;
string temp;
ifstream load_file;
load_file.open(filename.c_str());
if(!load_file.good())allegro_message("(1) LOAD FILE IS BAD! FLAGS SET\n EOF: %i \n BAD: %i \n FAIL: %i \n FILENAME.c_str(): %s", load_file.eof(),load_file.bad(),load_file.fail(),filename.c_str());
load_file>>temp>>W_num_frames;
W_ANI.assign(root_path);
W_ANI.append(temp);
load_file>>temp>>A_num_frames;
A_ANI.assign(root_path);
A_ANI.append(temp);
load_file>>temp>>D_num_frames;
D_ANI.assign(root_path);
D_ANI.append(temp);
if(!load_file.good())allegro_message("(2)LOAD FILE IS BAD! FLAGS SET\n EOF: %i \n BAD: %i \n FAIL: %i", load_file.eof(),load_file.bad(),load_file.fail());
rm->Load_Sprite(W_ANI,W_ANI);
rm->Load_Sprite(A_ANI,A_ANI);
rm->Load_Sprite(D_ANI,D_ANI);
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));
load_file>>num_col;
Hit_Zones = new C_Circ*[num_col];
multipliers = new int[num_col];
int cx,cy,cr;
for(int lcv = 0;lcv < num_col;lcv++)
{
load_file>>cx>>cy>>cr>>multipliers[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);
load_file.close();
}
It’s failing at the open. When you say spawn, I’m assuming you mean different threads, not new processes. I suspect you are running out of file descriptors, as there is a limit to the number of open files a given process may have.
When an open fails it sets the global value ERRNO. You can either get C++ fancy with it (using strerror(errno)) , or just use perror() to see whether this was the issue.