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 ➜ SMAUG ➜ SMAUG coding ➜ extended bitvectors and flag arrays

extended bitvectors and flag arrays

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


Posted by Ithildin   USA  (262 posts)  Bio
Date Wed 12 Jan 2005 02:19 AM (UTC)
Message
Ok, I have put spell memorization into my code, but when I mstat a player while he is meming a spell, the mud crashes.

Here is my backtrace:


(gdb) bt
#0  0x610cbb60 in strcpy () from /usr/bin/cygwin1.dll
#1  0x610cb9f5 in strcat () from /usr/bin/cygwin1.dll
#2  0x004909fb in ext_flag_string (bitvector=0x101fa814, flagarray=0x48feb0)
    at build.c:312
#3  0x004635f3 in do_mstat (ch=0x101f23f8, argument=0x22ea26 "gomer")
    at act_wiz.c:2002
#4  0x005266dc in interpret (ch=0x101f23f8, argument=0x22ea26 "gomer")
    at interp.c:550
#5  0x004c3f49 in game_loop () at comm.c:632
#6  0x004c31e7 in main (argc=1, argv=0x10010d60) at comm.c:286


In build.c:


char *ext_flag_string( EXT_BV *bitvector, char * const flagarray[] )
{
    static char buf[MAX_STRING_LENGTH];
    int x;

    buf[0] = '\0';
    for ( x = 0; x < MAX_BITS ; x++ )
	if ( xIS_SET( *bitvector, x ) )
	{
	    strcat( buf, flagarray[x] );
	    strcat( buf, " " );
	}
    if ( (x=strlen(buf)) > 0 )
	buf[--x] = '\0';
    
    return buf;
}


and my player_flags:


typedef enum
{
  PLR_IS_NPC,PLR_BOUGHT_PET, PLR_SHOVEDRAG, PLR_AUTOEXIT, PLR_AUTOLOOT, 
  PLR_AUTOSAC, PLR_BLANK, PLR_OUTCAST, PLR_BRIEF, PLR_COMBINE, PLR_PROMPT, 
  PLR_TELNET_GA, PLR_HOLYLIGHT, PLR_WIZINVIS, PLR_ROOMVNUM, PLR_SILENCE, 
  PLR_NO_EMOTE, PLR_ATTACKER, PLR_NO_TELL, PLR_LOG, PLR_DENY, PLR_FREEZE, 
  PLR_THIEF, PLR_KILLER, PLR_LITTERBUG, PLR_ANSI, PLR_RIP, PLR_NICE, PLR_FLEE, 
  PLR_AUTOGOLD, PLR_AUTOMAP, PLR_AFK, PLR_INVISPROMPT, PLR_MEMING, PLR_MEDITATE, PLR_CASTING
} player_flags;


I'm not really sure what's goin on here. Any thoughts?
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #1 on Wed 12 Jan 2005 02:43 AM (UTC)
Message
Did you add the correct references for the flag in build.c, the "display" name, etc?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #2 on Wed 12 Jan 2005 05:15 AM (UTC)
Message
Which line is 312, and did you update MAX_BITS? Could you give a little more info about the line in build.c where it crashed?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #3 on Wed 12 Jan 2005 08:28 AM (UTC)
Message
If line 312 is here
	    strcat( buf, flagarray[x] );
Please also try printing the values of x and the contents of flagarray.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Ithildin   USA  (262 posts)  Bio
Date Reply #4 on Wed 12 Jan 2005 11:30 AM (UTC)
Message
Here's my extended bit's:


#ifndef INTBITS
  #define INTBITS       35
#endif
#define XBM             31      /* extended bitmask   ( INTBITS - 1 )   */
#define RSV             5       /* right-shift value  ( sqrt(XBM+1) )   */
#define XBI             4       /* integers in an extended bitvector    */
#define MAX_BITS        XBI * INTBITS


Here are my plr_flags:


char *  const   plr_flags [] =
{
"npc", "boughtpet", "shovedrag", "autoexits", "autoloot", "autosac", "blank",
"outcast", "brief", "combine", "prompt", "telnet_ga", "holylight",
"wizinvis", "roomvnum","silence", "noemote", "attacker", "notell", "log",
"deny", "freeze", "thief","killer", "litterbug", "ansi", "rip", "nice",
"flee" ,"autogold", "automap", "afk", "invisprompt", "meming", "meditate", "casting"
};


312 is the line greven showed.
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #5 on Wed 12 Jan 2005 04:36 PM (UTC)
Message
Well, INTBITS should really be 32, as this is kind of an important number. This will affect how many flags you can have per integer(the types size in bytes * 8 bits per byte), so this should be 32, not 35, unless something is really, really messed up. This doesn't make sense as 35 either
#ifndef INTBITS
  #define INTBITS       35
#endif
#define XBM             31      /* extended bitmask   ( INTBITS - 1 )   */


That could be part of the problem, more likely its the value of x has overextended the boundries of flagarray, or something is wrong with buf. Can you print both of those and see what the values are?

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Ithildin   USA  (262 posts)  Bio
Date Reply #6 on Thu 13 Jan 2005 12:03 AM (UTC)
Message
It looks like I got it to work. It was the 35, needed to put that back at 32, made clean and recompiled. it seems to work now.

also, how would I have printed it out what the value of x was? I wasn't sure on what you were wanting me to do there. so for future reference, how do i do that.

Thanks
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #7 on Thu 13 Jan 2005 12:09 AM (UTC)
Message
In GDB you can print out the value of variable x by simply typing 'print x', where x is any variable in the visible scope. If x is a pointer, you can dereference it and print it by typing 'print *x'.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Ithildin   USA  (262 posts)  Bio
Date Reply #8 on Thu 13 Jan 2005 01:33 AM (UTC)
Message
Now i'm having trouble with showrace command. It's crashing as well now and i haven't even changed anything in that file. so I'm not sure what's up. Here's my bt:


Program received signal SIGSEGV, Segmentation fault.
0x001b9c29 in strcat () from /lib/tls/libc.so.6
(gdb) bt
#0  0x001b9c29 in strcat () from /lib/tls/libc.so.6
#1  0x0828d62c in new_boot_struct ()
#2  0x080afb8d in ext_flag_string (bitvector=0x8db7700, flagarray=0x81c58a0)
    at build.c:312
#3  0x080a3d2e in do_showrace (ch=0x8f3f1e8, argument=0xbff6182e "")
    at act_wiz.c:8730
#4  0x081132b6 in interpret (ch=0x8f3f1e8, argument=0xbff61829 "human")
    at interp.c:550
#5  0x080d689b in game_loop () at comm.c:632
#6  0x080d5eb6 in main (argc=1, argv=0xbff61d64) at comm.c:286


I'm still not sure what exactly i need to "print", I tried print buf, print strcat, but i'm not sure what else I can do with it. Sorry for being incompetent still.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #9 on Thu 13 Jan 2005 02:07 AM (UTC)
Message
BTs are only useful in finding out which functions were called when. The next step is to look at the line of code that's broken (assuming it's that simple, which in SMAUG, it usually is.) Generally you'll have variables with bad values, and you use the print command to determine what their values are.

To print, the variable has to be in the current scope. You navigate the call stack (the stuff in the backtrace) using 'up' and 'down' to move from frame to frame. And then, you can use the print command on that function's variables.

I strongly suggest that you read Nick's guide to GDB; it explains this and much else in great detail. Don't skip over stuff just because you think you know it. :P

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
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.


23,832 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.