Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ Programming ➜ General ➜ New problem, any information would be good

New problem, any information would be good

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


Posted by Trom   (82 posts)  Bio
Date Thu 08 Apr 2004 07:09 AM (UTC)
Message
Now i've been posting a lot in this forum the last few months. The only probs i bring up here is ones i can't figure out after trying for at least a day. Now most errors in gdb seem to be segmentation fault or something like that. But this one is new.

Program received signal SIGFPE, Arithmetic exception.
0x00499216 in new_saves_spell (ch=0xdbed88, victim=0xdbed88, dam_type=9)
at magic.c:229
229 save = ( (vic_save * 100) / (ch_save + vic_save) );


The problem occurs when, as a mortal i try to cast curse on myself (some people might try that) and it crashes the mud. In gdb it gives the above error "arithmetic exception". I've re-arranged the formula, checked the values of vic_save, ch_save, ch, victim, and its all done correctly... I just don't get why this error would come up. I've even made the values into variable then did the division, still the same prob.



Backtrace shows this:
(gdb) bt
#0 0x00499216 in new_saves_spell (ch=0xdbed88, victim=0xdbed88, dam_type=9)
at magic.c:229
#1 0x0049deb5 in spell_curse (sn=60, level=129, ch=0xdbed88, vo=0xdbed88,
target=0) at magic.c:1922
#2 0x0049a7e1 in do_cast (ch=0xdbed88, argument=0xdbe0a2 "curse self")
at magic.c:780
#3 0x00497c8c in interpret (ch=0xdbed88, argument=0xdbe09d "cast curse self")
at interp.c:669
#4 0x0044144c in substitute_alias (d=0xdbd720,
argument=0xdbe09d "cast curse self") at alias.c:107
#5 0x00449bdb in game_loop_unix (control=4, wwwcontrol=5) at comm.c:905
#6 0x00449478 in main (argc=1, argv=0xb113b0) at comm.c:472


Top

Posted by Trom   (82 posts)  Bio
Date Reply #1 on Thu 08 Apr 2004 07:11 AM (UTC)

Amended on Thu 08 Apr 2004 07:13 AM (UTC) by Trom

Message
This is the problem function (not sure why its a prob):

bool new_saves_spell ( CHAR_DATA * ch, CHAR_DATA * victim, int dam_type )
{
int save = 0, vic_save = 0, ch_save = 0;

ch_save = IS_NPC(ch) ? ch->level/20 : ch->pcdata->saves;
vic_save = IS_NPC(victim) ? victim->level/20 : victim->pcdata->saves;

// if the victim of the saving throw is berserked, they can't defend as well
if ( IS_AFFECTED ( victim, AFF_BERSERK ) )
vic_save -= 2;

switch ( check_immune ( victim, dam_type ) )
{
case IS_IMMUNE:
return TRUE;
case IS_RESISTANT:
vic_save += 8;
break;
case IS_VULNERABLE:
vic_save -= 8;
break;
}

save = ( (vic_save * 100) / (ch_save + vic_save) );

return number_percent() < save;
}
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 08 Apr 2004 09:08 AM (UTC)
Message
What is ch_save + vic_save equal to? Zero? You might be dividing by zero.

Check that out in gdb. When you get the exception type:

print ch_save + vic_save

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Trom   (82 posts)  Bio
Date Reply #3 on Thu 08 Apr 2004 03:14 PM (UTC)
Message
Thanks, that was the problem. The base saves were 0, forgot that can be a problem in division. Thanks
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.


13,539 views.

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

Go to topic:           Search the forum


[Go to top] top

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