My program recently started crashing when I added a file-load loop, but only when the file contains so-much data. I'm wondering if its looping to much without a sleep function, will this cause crashs?
->Nm, I think this is solved. Sorry!
This is a discussion on Overloop question? within the C++ Programming forums, part of the General Programming Boards category; My program recently started crashing when I added a file-load loop, but only when the file contains so-much data. I'm ...
My program recently started crashing when I added a file-load loop, but only when the file contains so-much data. I'm wondering if its looping to much without a sleep function, will this cause crashs?
->Nm, I think this is solved. Sorry!
Last edited by Blackroot; 08-19-2006 at 03:08 AM.
Code:Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)
I cannot say for sure, but programs don't need rest. Segfault perhaps? Can't do much except guessing without some code though.
Hmm, I tried adding some sleeps, I dont know why it would be an issue.
I have two renditions, both crash, but seperate programs use them.
The second rendition is the same, except at the end EraseExtra() and FindPlayerPos() are replaced with:Code://*Globals: COORD TE[1000]; //Teleporter Enterence array COORD TD[1000]; //Teleporter Destination array int NOE = 0; //Number of Teleporter Enterences int NOD = 0; //Number of Teleporter Destinations COORD Trigger[1000]; //Trigger Array int NOT = 0; //Number of Triggers COORD Effect[1000]; //Trigger Effect Array int NOTE = 0; //Number of Trigger Effects COORD OldCharPos[1000];//Old char positions for effects char OldChar[1][1000]; //Old chars for effects HANDLE hOt = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO inf; CONSOLE_CURSOR_INFO Cur; WORD Scolor; WORD Scurso; char CurPeice; int Ticker, MOUSEX, MOUSEY; COORD RSP; char Ext; void Load(char Ext) { string MAP; string PATH; char Saveme[2]; char DIRFIL[501]; unsigned x00; string s, s2, ko; BOOL sswitch = false; int i, a; stringstream ss; clrscr(); PATH="C:\\"; PATH+=Ext; PATH+=".txt"; ifstream file_in(PATH.c_str(), ios::nocreate); if(!file_in) { cout << "Critical Error[1]: Could not find map file."; exit(0); } clrscr(); for(x00=0; x00 < 2026; x00++) { file_in.get(Saveme[0]); if(Saveme[0] == 0) break; MAP+=Clerify(Saveme[0]); } for(x00=0; x00 < 2026; x00++) { if(MAP[x00] == Enemy1 || MAP[x00] == Enemy2 || MAP[x00] == Enemy3 || MAP[x00] == Enemy4 ||MAP[x00] == Wall10) { SetColor('r'); cout << MAP[x00]; SetColor('o'); } else if(MAP[x00] == Player) { SetColor('g'); cout << MAP[x00]; SetColor('o'); } else if(MAP[x00] == ExitPeice) { SetColor('s'); cout << MAP[x00]; SetColor('o'); Coins++; } else cout << MAP[x00]; } PATH="C:\\"; PATH+=Ext; PATH+=".bsf"; ifstream file_in2(PATH.c_str(), ios::nocreate); s=""; for(;;) { Sleep(1); file_in2.get(Saveme[1]); if(Saveme[1] == 'a') break; if(Saveme[1] == ';') sswitch = true; if(Saveme[1] == ';' || Saveme[1] == 'n' ||Saveme[1] == 'e' ||Saveme[1] == '\n') cout << ""; else { if(sswitch == false) s+=Saveme[1]; else s2+=Saveme[1]; } } a = 0; ko = ""; for(i=0; a < s.length(); i++) { Sleep(1); ss.clear(); ss.str(""); ko = s.substr(a,2); ss << ko; ss >> TE[i].X; a+=2; ss.clear(); ss.str(""); ko = s.substr(a,2); ss << ko; ss >> TE[i].Y; a+=2; NOE++; NOD++; ss.clear(); ss.str(""); ko = s.substr(a,2); ss << ko; ss >> TD[i].X; a+=2; ss.clear(); ss.str(""); ko = s.substr(a,2); ss << ko; ss >> TD[i].Y; a+=2; } a = 0; ko = ""; for(i=0; a < s2.length(); i++) { Sleep(1); ss.clear(); ss.str(""); ko = s2.substr(a,2); ss << ko; ss >> Trigger[i].X; a+=2; ss.clear(); ss.str(""); ko = s2.substr(a,2); ss << ko; ss >> Trigger[i].Y; a+=2; NOT++; NOTE++; ss.clear(); ss.str(""); ko = s2.substr(a,2); ss << ko; ss >> Effect[i].X; a+=2; ss.clear(); ss.str(""); ko = s2.substr(a,2); ss << ko; ss >> Effect[i].Y; a+=2; } file_in2.close(); EraseExtra(); FindPlayerPos(); }
1.bsf seems to be causing trouble. When I delete most of its contents the program loads. Otherwise it crashs.Code:for(a=0; a <= NOE; a++) { wha.X = TE[a].X; wha.Y = TE[a].Y; SetConsoleCursorPosition(hOt, wha); cout << TeleportE; } for(a=0; a <= NOD; a++) { wha.X = TD[a].X; wha.Y = TD[a].Y; SetConsoleCursorPosition(hOt, wha); cout << TeleportD; } for(a=0; a <= NOT; a++) { wha.X = Trigger[a].X; wha.Y = Trigger[a].Y; SetConsoleCursorPosition(hOt, wha); cout << TriggerE; } for(a=0; a <= NOTE; a++) { wha.X = Effect[a].X; wha.Y = Effect[a].Y; SetConsoleCursorPosition(hOt, wha); cout << TriggerP; } file_in2.close();}
1.txt has loaded sence fine sence I made the program.Code:4219n4318e 4320n4417e 4419n4516e 4518n1405e 1206n7805e 7807n7419e ; 1921n0216e 2221n2016e 2521n0196e 2721n0186e a
It doesnt make sence why it loads when 1.bsf has less in it, and crashs otherwise?
Code:Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)
I dont know why, but I solved the issue. Rather than overlooping, or being a problem with loading, it was a problem with saving. I saved numbers less than 10 as... Just that. Instead of what I should of as 0#. When I added a little failsafe for it, and placed tons of coords in the file, it worked fine. I dont know why that fixed it, but it did -,-.
Sorry for bothering you >.>.
Code:Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)
If your code for reading a file assumes the file is in a particular format, then it will probably behave strangely if the file is actually in a different format. Putting in Sleep() statements to slow it down will not change that.
I would suggest you need to put in a few checks to make sure the input file is actually in the correct form --- either before reading it, or while reading it. Of course, that requires you to precisely specify what the format is.