[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Annoying crash bug - please help! :(
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Annoying crash bug - please help! :(

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Syriac   (46 posts)  [Biography] bio
Date Fri 19 Jun 2009 10:55 PM (UTC)

Amended on Fri 19 Jun 2009 10:56 PM (UTC) by Syriac

Message
Hello time to pick your wonderful brains again...

I've written a bit of code that basically determines how powerful a clan is by compiling some information together and doing some simple math - I had it working but for some reason, it just stopped. It crashes every time it calls to the function - here's the dead line...

Program received signal SIGSEGV, Segmentation fault.
0x00000000004b2f9a in update_flipower (ch=0x105ca40) at fli.c:686
686 mbrs += ch->pcdata->clan->members;
(gdb) bt
#0 0x00000000004b2f9a in update_flipower (ch=0x105ca40) at fli.c:686
#1 0x0000000000409880 in do_save (ch=0x105ca40, argument=0x7fffffffe1b2 "") at act_comm.c:2462
#2 0x00000000004cced5 in interpret (ch=0x105ca40, argument=0x7fffffffe1b2 "") at interp.c:740
#3 0x00000000004406b8 in do_force (ch=0x102da80, argument=0x7fffffffe1ae "save") at act_wiz.c:6280
#4 0x00000000004cced5 in interpret (ch=0x102da80, argument=0x7fffffffe1a6 "belerik save") at interp.c:740
#5 0x000000000047fe11 in game_loop () at comm.c:684
#6 0x000000000047f2e0 in main (argc=1, argv=0x7fffffffe768) at comm.c:331


here's the entire function

void update_flipower( CHAR_DATA *ch )
{
int flipower = 0;
int mbrs = 0;

        // check to see if they're retired and terminate if so
        if ((ch->level == 55 || ch->level == 57) && IS_RETIRED(ch))
        {
                return;
        }

 	if ((ch->level == 55 || ch->level == 57) && !IS_RETIRED(ch))
        {
                mbrs += ch->pcdata->clan->members;
                //flipower += ch->pcdata->clan->members * 2;
                flipower += mbrs * 2;

                // max out member points at 100
                if (flipower > 100)
                {
                        flipower = 100;
                }

                flipower += ch->pcdata->clan->balance / 7500;

                if (flipower > 200)
                {
                        flipower = 200;
                }

                if (ch->level == 57)
                {
                        flipower += 50;
                }

                ch->pcdata->clan->powerlvl += flipower;
                return;
        }
        return;
}

[Go to top] top

Posted by Syriac   (46 posts)  [Biography] bio
Date Reply #1 on Fri 19 Jun 2009 11:17 PM (UTC)
Message
Another question is do I need to have the void update_flipower( CHAR_DATA *ch ) in the external functions for act_comm.c (where do_save is?) The frustrating part is this did work earlier and updatef the powerlvl in the clan files correctly... Gah...
[Go to top] top

Posted by Nick Gammon   Australia  (21,323 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Fri 19 Jun 2009 11:46 PM (UTC)
Message
It crashes on a line that dereferences a pointer. In gdb you need to see if it is valid. eg


p ch->pcdata
p ch->pcdata->clan


If either is NULL, then you would expect a crash.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #3 on Fri 19 Jun 2009 11:48 PM (UTC)
Message
What is line 686?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Syriac   (46 posts)  [Biography] bio
Date Reply #4 on Fri 19 Jun 2009 11:56 PM (UTC)
Message
 	if ((ch->level == 55 || ch->level == 57) && !IS_RETIRED(ch))
        {
      -->THIS LINE          mbrs += ch->pcdata->clan->members;
                //flipower += ch->pcdata->clan->members * 2;
                flipower += mbrs * 2;
[Go to top] top

Posted by Syriac   (46 posts)  [Biography] bio
Date Reply #5 on Fri 19 Jun 2009 11:59 PM (UTC)

Amended on Sat 20 Jun 2009 12:02 AM (UTC) by Syriac

Message
(gdb) p ch->pcdata
$1 = (PC_DATA *) 0x10570a0

(gdb) p ch->pcdata->clan
$2 = (CLAN_DATA *) 0x0


I'm not sure what this means or how to fix it :-/
[Go to top] top

Posted by Syriac   (46 posts)  [Biography] bio
Date Reply #6 on Sat 20 Jun 2009 12:29 AM (UTC)
Message
Tried to change it... same thing, CLAN_DATA 0X0


1 Follower = 2 points
7500 gold = 1 point

< 10 = Cult Power == 1 OM x1 Mana Regen
< 50 = Demi Power == 1 OM X1.1 Mana Regen
< 100 = Lesser Power == 2 OM X1.5 Mana Regen
< 150 = Intermediate Power == 2 OM X2 Mana Regen
<= 200 = Greater Power == 3 OM X3 Mana Regen


Program received signal SIGSEGV, Segmentation fault.
0x00000000004b2fa6 in update_flipower (ch=0x1056630) at fli.c:687
687			members += ch->pcdata->clan->members;
Missing separate debuginfos, use: debuginfo-install glibc-2.9-3.x86_64
(gdb) bt
#0  0x00000000004b2fa6 in update_flipower (ch=0x1056630) at fli.c:687
#1  0x0000000000409880 in do_save (ch=0x1056630, argument=0x7fffffffe1a4 "") at act_comm.c:2462
#2  0x00000000004ccee1 in interpret (ch=0x1056630, argument=0x7fffffffe1a4 "") at interp.c:740
#3  0x000000000047fe1d in game_loop () at comm.c:684
#4  0x000000000047f2ec in main (argc=1, argv=0x7fffffffe768) at comm.c:331


void update_flipower( CHAR_DATA *ch )
{
int flipower = 0;
int mbrs = 0;
int penalty1 = 0;
int bonus = 0;
CLAN_DATA *clan;

        // check to see if they're retired and terminate if so
        if ((ch->level == 55 || ch->level == 57) && IS_RETIRED(ch))
        {
                return;
        }
   
        if ((ch->level == 55 || ch->level == 57) && !IS_RETIRED(ch))
        {
                clan = ch->pcdata->clan;
   
                // Get value for number of members
                mbrs += clan->members;
                flipower += mbrs * 2;
    
                // Calculate value from following balance
                flipower += clan->balance / 7500;

                // Penalty for NPC deaths
                penalty1 += clan->mdeaths * 1.5;
                flipower += penalty1;

                // Plus 50 bonus for being Lesser God(dess)
                if (ch->level == 57)
                {
                        flipower += 50;
                }

                // Determine bonus for PKills.
                bonus += ((clan->pkills[6] + clan->pkills[2] +
                           clan->pkills[3] + clan->pkills[4] +
                           clan->pkills[5] + clan->pkills[0] +
                           clan->pkills[1]) * .5);
                flipower += bonus;

                // Set it and forget it
                clan->powerlvl += flipower;
                save_clan( clan );
                return;
        }
        return;

}
[Go to top] top

Posted by Syriac   (46 posts)  [Biography] bio
Date Reply #7 on Sat 20 Jun 2009 12:38 AM (UTC)
Message
I figured it out - instead of having clans be looked up by clan name I had it look up by deity, this meant the deitys needed to have their clans reset.
[Go to top] top

Posted by Conner   USA  (381 posts)  [Biography] bio
Date Reply #8 on Sat 20 Jun 2009 12:43 AM (UTC)
Message
I don't know about your deities, but that 0x0 is the NULL Nick was talking about.

-=Conner=-
--
Come test your mettle in the Land of Legends at telnet://tcdbbs.zapto.org:4000
or, for a little family oriented medieval fun, come join us at The Castle's Dungeon BBS at telnet://tcdbbs.zapto.org
or, if you just want information about either, check our web page at http://tcdbbs.zapto.org
[Go to top] top

Posted by Syriac   (46 posts)  [Biography] bio
Date Reply #9 on Sat 20 Jun 2009 12:46 AM (UTC)
Message
Yes it was 0X0 because I have god lead clans on my MUD, so the gods clan data was null as I had to update their files.
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #10 on Sat 20 Jun 2009 07:46 AM (UTC)

Amended on Sat 20 Jun 2009 07:41 PM (UTC) by Nick Cash

Message
-Any- character not in a clan will cause it to crash since their clan pointer will be NULL (0x0). While reseting stuff may make things work now, you aren't really fixing the crash problem itself. You should be checking to see if a character has a valid clan pointer and then proceed if they do, such as...


if ((ch->level == 55 || ch->level == 57) && !IS_RETIRED(ch))
{
    if ( ch->pcdata && ch->pcdata->clan )
    {
        clan = ch->pcdata->clan;
   
        // Get value for number of members
        mbrs += clan->members;
        flipower += mbrs * 2;

        // etc...
    }
}


Such checks are used to make sure your pointer is indeed pointing to an address instead of to NULL. If you try to access the data of any NULL pointer you will get a crash as Nick said. Thus, it is a good idea to always validate your pointers before using them. I do not know how you are calling this function, but it may be wise to validate ch->pcdata as well in case you one of your NPCs finds a way to the function when he shouldn't. If that happens and you don't have the check the game will crash again.

I should also note that since you are working with a function that returns void you do not need to explicitly write a return statement (and generally it is good practice to limit yourself to one, although SMAUG certainly doesn't adhere to that or any other coding standard). Removing both of your return statements should not affect your code :)

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Syriac   (46 posts)  [Biography] bio
Date Reply #11 on Sat 20 Jun 2009 07:58 PM (UTC)
Message
Yes, I forgot to mention I added a (!clan) statement to prevent crashes too. Thanks for the help guys :)
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


8,342 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]