Hehe ok I feel really kinda silly.... problem was I was deleting the same
pointer twice.... I think I might need a break for awail I can't belive I
didn't see that....

----- Original Message -----
From: "Dale Kingston" <[EMAIL PROTECTED]>
To: "ROM" <[email protected]>
Sent: Monday, November 04, 2002 1:50 PM
Subject: Memory allocation question


> Ok I have a small problem. I'm currently rewriting our current quest mob
> code. To be objected based, and I'm hitting a problem that I don't get why
> it's doing it.
>
> Ok with the code I have you find a mob in the world and assign it to be a
> quest mob. It runs throught this check:
>  if (!str_cmp(arg, "assign"))
>  {
>   for (questmob = ch->in_room->people; questmob != NULL; questmob =
> questmob->next_in_room)
>   {
>    if (is_name(arg2, questmob->name))
>     break;
>   }
>   if (questmob == NULL)
>   {
>    send_to_char("Their is no one in the room by that name.\n\r", ch);
>    return;
>   }
>   STR_SET_BIT(questmob->act, ACT_QUEST_MASTER);
>   STR_SET_BIT(questmob->pIndexData->act, ACT_QUEST_MASTER);
>   SET_BIT(questmob->in_room->area->area_flags, AREA_CHANGED);
>   questmaster = new (QUEST_DATA);
>   questmaster->questmob = questmob;
>   if (questmaster_table == NULL)
>    questmaster_table = questmaster;
>   else
>   {
>    questmaster->next = questmaster_table;
>    questmaster_table = questmaster;
>   }
>   printf_to_char(ch, "%s is a new Quest Master!\n\r",
> questmob->short_descr);
>   return;
>
>  }
> Now I know that is running properly. Now cause I was testing the making
and
> deleteing of the mob I then told it to unassign the quest mob and it runs
> through this.
>  if (!str_cmp(arg, "unassign"))
>  {
>   if ((questmaster = locate_questmaster(ch)) == NULL)
>   {
>    send_to_char("Their is no Quest Master in the room.\n\r", ch);
>    return;
>   }
>   if (questmaster->questmob == NULL)
>   {
>    send_to_char("Their is no one in the room by that name.\n\r", ch);
>    return;
>   }
>   STR_REMOVE_BIT(questmaster->questmob->pIndexData->act,
ACT_QUEST_MASTER);
>   SET_BIT(questmaster->questmob->in_room->area->area_flags, AREA_CHANGED);
>   printf_to_char(ch, "%s is nolonger a Quest Master!\n\r",
> questmaster->questmob->short_descr);
>   for (curr = questmaster_table, prev = NULL; curr != NULL; prev = curr,
> curr = curr->next)
>   {
>    if (curr == questmaster)
>    {
>     if (prev == NULL)
>     {
>      delete questmaster_table;
>      questmaster_table = NULL;
>      break;
>     }
>     else
>     {
>      prev->next = curr->next;
>      delete curr;
>      break;
>     }
>    }
>   }
>   extract_char(questmaster->questmob, TRUE);
>   delete questmaster;
>   return;
>  }
>
> Now heres my problem I'm using C++ and using constructors and
deconstructors
> and the problem I'm hitting is this when it hits the decontrutor it goes
> through the remove all quests currently in the mobs memory. But the
problem
> is their wasn't any current quest running I allocated him and then deleted
> him.
>
> Heres my constructor:
> quest_data ::quest_data()
> {
>  memset(this, 0, sizeof(*this));
>  this->qArea_list = NULL;
>  this->current_quests = NULL;
>  this->quest_item_table = NULL;
>  return;
> }
> and Heres my deconstrcutor
> quest_data ::~quest_data()
> {
>  QUEST_TABLE_DATA *quest;
>  struct quest_area_type *list, *next_in_list;
>
>  free(this->quest_item_table);
>
>  for (quest = this->current_quests; quest != NULL; quest = quest->next)
>   this->remove_quest(quest);
>
>  for (list = this->qArea_list; list != NULL; list = next_in_list)
>  {
>   next_in_list = list->next;
>   free(list);
>  }
>
>  return;
> }
> and heres what GDB is telling me what happened:
> #0  0x080eef79 in quest_data::remove_quest (this=0x8229270,
> entry=0x4018ac48)
>     at olc_qedit.cc:883
> 883                             curr->player->pcdata->nextquest = 10;
> (gdb) bt
> #0  0x080eef79 in quest_data::remove_quest (this=0x8229270,
> entry=0x4018ac48)
>     at olc_qedit.cc:883
> #1  0x080ee6d2 in quest_data::~quest_data (this=0x8229270, __in_chrg=3)
>     at olc_qedit.cc:614
> #2  0x080f0a7c in do_assign_questmaster (ch=0x40cfea94,
>     argument=0xbfffe99c "unassign guard") at olc_qedit.cc:1788
> 878
> 879             for (curr = this->current_quests; curr != NULL; prev =
curr,
> cur
> r = curr->next)
> 880             {
> 881                     if(curr == entry)
> 882                     {
> 883                             curr->player->pcdata->nextquest = 10;
> 884                             if
(curr->player->PlrFlagged(PLR_QUESTING));
> 885                                     printf_to_char(curr->player, "You
> have r
> un out of time for your quest!\n\rYou may quest again in %d minutes.\n\r",
> curr-
> >player->pcdata->nextquest);
> 886                             curr->player->PlrRemoveBit(PLR_QUESTING);
> 887                             curr->player->pcdata->questmaster = NULL;
> (gdb) print this->current_quests
> $1 = (QUEST_TABLE_DATA *) 0x4018ac48
> (gdb) print this->questmob
> $2 = (CHAR_DATA *) 0x40a60010
> (gdb) print this->questmob->name
> $3 = 0x40216c7f "Guardian"
> (gdb)
>
> Now with the constructor setting all the pointers to NULL why did it pass
> it's check in the deconstructor? Did I do something wrong or forget to do
> something?
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>


Reply via email to