Thread: Overloop question?

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Overloop question?

    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 *)

  2. #2
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    I cannot say for sure, but programs don't need rest. Segfault perhaps? Can't do much except guessing without some code though.

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    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.

    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();
    }
    The second rendition is the same, except at the end EraseExtra() and FindPlayerPos() are replaced with:

    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.bsf seems to be causing trouble. When I delete most of its contents the program loads. Otherwise it crashs.

    Code:
    4219n4318e
    4320n4417e
    4419n4516e
    4518n1405e
    1206n7805e
    7807n7419e
    
    ;
    1921n0216e
    2221n2016e
    2521n0196e
    2721n0186e
    
    a
    1.txt has loaded sence fine sence I made the program.

    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 *)

  4. #4
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    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 *)

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM