On Tue, 29 Apr 2003, Tristan M wrote:
> yeah, me again, i'm still hacking away at this player owned shop thing, my
> problem now is making the mob a shop... here's a chunk of the code:
>
> mobVnum = ch->in_room->vnum;
> pRoom = ch->in_room;
> pMobIndex = get_mob_index( ch->in_room->vnum);
>
> sprintf(buf,"{cA shopkeeper for {C%s{c's store.{x",ch->in_room->owner);
> pMobIndex->short_descr = str_dup( buf );
>
> /* set the shopkeepers short/long/name and act bits */
> sprintf(buf,"{cA shopkeeper for {C%s{c's store.{x",ch->in_room->owner);
> pMobIndex->short_descr = str_dup( buf );
> sprintf(buf,"{cA shopkeeper for {C%s{c's store.{x",ch->in_room->owner);
> pMobIndex->long_descr = str_dup( buf);
> sprintf(buf,"player owner shopkeeper");
> pMobIndex->player_name = str_dup( buf );
> pMobIndex->hit[DICE_NUMBER] = 10;
> pMobIndex->hit[DICE_TYPE] = 10;
> pMobIndex->hit[DICE_BONUS] = 10;
> pMobIndex->mana[DICE_NUMBER] = 10;
> pMobIndex->mana[DICE_TYPE] = 10;
> pMobIndex->mana[DICE_BONUS] = 10;
> pMobIndex->pShop->keeper = pMobIndex->vnum; /*Line Crashes Game*/
> pMobIndex->pShop->buy_type[ 4 ] = 4; /*Line Crashes Game*/
> pMobIndex->pShop->open_hour = 1; /*Line Crashes Game*/
> pMobIndex->pShop->close_hour = 24; /*Line Crashes Game*/
> pMobIndex->pShop->keeper = mobVnum; /*Line Crashes Game*/
> pMobIndex->pShop->next = NULL; /*Line Crashes Game*/
> pMobIndex->pShop->profit_buy = 100; /*Line Crashes Game*/
> pMobIndex->pShop->profit_sell = 100; /*Line Crashes Game*/
>
>
>
> everything with /*Line Crashes Game*/ is where the mud gets crashed...it
> compiles error and warning free and since i'm not exactly experienced i'm
> just lost...it looks like it should make sense to me...anyone know?
>
Do you notice anything special about every line it crashes on that's
different than the ones it doesn't crash on?
A "crash" is what happens when your program tries to access a memory
address the operating system hasn't given your program the right to access,
by dereferencing a pointer with a bad address in it. Since your
program is trying to do something it hasn't been given permission to
do, the operating system sends it a signal, which by default kills
the program.
The two most common causes of a crash are dereferencing a NULL pointer
(NULL is guaranteed to be an address you don't have access to), and
using a pointer that has been accidentaly overwritten by a buffer
overflow. In my experience, it's usually a NULL pointer.
You dereference a pointer using the * symbol: "*pointer", or if it's
a pointer to a structure you can use the -> symbol: "pointer->field"
is an abbreviation for "(*pointer).field".
Hopefully by this point you've figured out why it's crashing.
You should know what it's doing that it shouldn't be doing.
You just have to figure out how to make it correct (hint: make
sure your pointers are pointing to valid memory locations, by
allocating memory if necessary, before using them).
Dennis