Thread: Crashing and load data errors

  1. #1
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105

    Crashing and load data errors

    A text-based game I'm working on is having several bugs I can't find. The battle system crashes the game if the user inputs the command to "block" or after a few commands and the load method fails to load any of the saved data. It's a long file so I'll just put up the source code as an attachment so you can all critique my horrific coding style. The code complies correctly but I can't find the run-time bugs in the code.

    On a semi-unrelated note, my Dev-C++ 4.9.9.2 has been randomly freezing recently, so that I have to kill the process. Any help with that?
    Hatman Approves!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, first of all, the code looks pretty good (if a little inefficient). Unfortunately, I don't really have time to examine the whole thing, but the first thing that comes to mind is that you may be dividing by zero in some of the code, ie: 'rand()%Player.attack'. Aside from that, everything looks fairly tight. Maybe someone else will be able to scrutinize it closer, though. Good luck.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> On a semi-unrelated note, my Dev-C++ 4.9.9.2 has been randomly freezing recently, so that I have to kill the process. Any help with that?

    Not sure. But if nothing else, you can invoke it's compiler directly from the command line. Just navigate to the project folder and then compile with something like:

    c:\MyDevC++Path\bin\g++ -I "MY_INCLUDE_PATH" -Wall -pedantic -o battle_test_v_2.exe battle_test_v_2.cpp

    Or better yet, put in in a makefile or an MSDOS batch file.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    On a semi-unrelated note, my Dev-C++ 4.9.9.2 has been randomly freezing recently, so that I have to kill the process. Any help with that?
    It has been a very long time, but I think WxDev-C++ fixed the issue.

    On the source side of things:

    Code:
    unarmed.attack1maxhit=2;
    unarmed.attack2maxhit=3;
    unarmed.attack3maxhit=3;
    unarmed.attackname1="Chop";
    unarmed.attackname2="Punch";
    unarmed.attackname3="Kick";
    unarmed.weaponname="Unarmed";
    unarmed.defensebonus=2;
    is the same as:

    Code:
    weapons unarmed = {2, 3, 3, "Chop", "Punch", "Kick", "Unarmed", 2};
    and

    Code:
    playerweapon.attack1maxhit=unarmed.attack1maxhit;
    playerweapon.attack2maxhit=unarmed.attack2maxhit;
    playerweapon.attack3maxhit=unarmed.attack3maxhit;
    playerweapon.defensebonus=unarmed.defensebonus;
    playerweapon.weaponname=unarmed.weaponname;
    playerweapon.attackname1=unarmed.attackname1;
    playerweapon.attackname2=unarmed.attackname2;
    playerweapon.attackname3=unarmed.attackname3;
    is the same as:

    Code:
    playerweapon = unarmed;
    and

    Code:
       switch(Player.choice)
       {
          case 1:
          {
             playerweapon = unarmed;
          }
          break;
       }
       switch(opp.choice)
       {
          case 1:
          {
             oppweapon = unarmed;
          }
          break;
       }
    is the same as

    Code:
    void go(int choice, weapons & cw)
    {
       switch(choice)
       {
          case 1:
          {
             cw = unarmed;
          }
          break;
       }
    }
    //...
    go(Player.choice, playerweapon);
    go(opp.choice, oppweapon);
    Soma

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by DarkAlex View Post
    On a semi-unrelated note, my Dev-C++ 4.9.9.2 has been randomly freezing recently, so that I have to kill the process. Any help with that?
    If you insist on using and IDE, why not use Code::Blocks? Dev-C++ is a dead product.

    Re: the problem, have you recreated it in the debugger?
    Last edited by medievalelks; 03-20-2009 at 05:01 AM.

  6. #6
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    Thank you for your help with fixing my coding style. The problems I had with my program were that I had not set a value for maxdef for either character, and the load error was because I forgot to change the file extension that the game would look for. My Dev C++ IDE hasn't crashed since my first post.
    Hatman Approves!

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by DarkAlex View Post
    A text-based game I'm working on is having several bugs I can't find. The battle system crashes the game if the user inputs the command to "block" or after a few commands and the load method fails to load any of the saved data. It's a long file so I'll just put up the source code as an attachment so you can all critique my horrific coding style. The code complies correctly but I can't find the run-time bugs in the code.
    The first step in finding a crash is to watch the crash occur in a debugger. Once you've isolated the line of code, you can start to figure out where the bad data is coming from.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 11:29 AM
  2. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM