Re: [Code] Help bug

From: John (witpens@optushome.com.au)
Date: 11/29/01


Sorry for this guys (and gals),

I am going to try to expand on the crash I am having. I have basically
created a linked list of rooms that have special effects and running the
timer on each of these rooms. Once the timer has expired, the special
effects gets wiped off the linked list, and the room also gets freed.

LOGIC:-
When a new room is created, its created at:
RECREATE(world, struct room_data, top_of_world + 2);
top_of_world++;
and the new room will be world[top_of_world] with its vnum set at a top
zone.

Now, once I go thru the linked list of special effects, one of these
special rooms will be deleted. so. if world[i] was to be deleted:-
free(world[i]) and all its pointers (this works fine)
all rooms above world[i] will be moved down one and all objects and
chars moved down one as well.
free(world[top_of_world]); (this crashes here)
top_of_world--;

Thanks for any help. :)


void extract_room(room_vnum room)
{
  int i, k;
  room_vnum j;
  struct extra_descr_data *desc, *desc_next;

  struct char_data *tch;
  struct obj_data *tobj;

 if (world[room].name)
  free(world[room].name);
 if (world[room].description)
  free(world[room].description);
 if (world[room].func)  /* hope specials do not apply to other rooms */
  free(world[room].func);

 for (i = 0; i < NUM_OF_DIRS; i++)
  if (world[room].dir_option[i] != NULL)
   extract_exit(room, i);

 if (world[room].ex_description) {
  for (desc = world[room].ex_description; desc; desc = desc_next) {
   desc_next = desc->next;
   if (desc->description)
    free (desc->description);
   if (desc->keyword)
    free (desc->keyword);
   free(desc);
  }
 }


 for (j = room; j < top_of_world; j++) {
  world[j] = world[j+1];
 /* People in this room must have their in_rooms moved down one. */
  for (tch = world[j].people; tch; tch = tch->next_in_room)
   IN_ROOM(tch) -= (IN_ROOM(tch) != NOWHERE);

      /* Move objects too. */
  for (tobj = world[j].contents; tobj; tobj = tobj->next_content)
   IN_ROOM(tobj) -= (IN_ROOM(tobj) != NOWHERE);
 }
#define W_EXIT(r, e) (world[r].dir_option[e])
 /* changing exits to match the room being deleted */
 for (i = top_of_world; i >= 0; i--)
  for (k = 0; k < NUM_OF_DIRS; k++)
   if (W_EXIT(i, k)) {
    if (W_EXIT(i, k)->to_room > room)
     W_EXIT(i, k)->to_room--;
    else if (W_EXIT(i, k)->to_room == room)
     extract_exit(i, k);
   }
 /* Now top room is empty since we copied everything down one */
 extract_top_room();
}

void extract_top_room(void)
{
  int i, k;
  struct extra_descr_data *desc, *desc_next;

 if (world[top_of_world].name)
  free(world[top_of_world].name);
 if (world[top_of_world].description)
  free(world[top_of_world].description);
 if (world[top_of_world].func)  /* hope specials do not apply to other
rooms */
  free(world[top_of_world].func);

 for (i = 0; i < NUM_OF_DIRS; i++)
  if (world[top_of_world].dir_option[i])
   extract_exit(top_of_world, i);


 if (world[top_of_world].ex_description) {
  for (desc = world[top_of_world].ex_description; desc; desc =
desc_next) {
   desc_next = desc->next;
   if (desc->description)
    free (desc->description);
   if (desc->keyword)
    free (desc->keyword);
   free(desc);
  }
 }

 for (i = top_of_world; i >= 0; i--)
  for (k = 0; k < NUM_OF_DIRS; k++)
   if (W_EXIT(i, k))
    W_EXIT(i, k)->to_room -= (W_EXIT(i, k)->to_room >= top_of_world);
 RECREATE(world, struct room_data, top_of_world);
 top_of_world--;
}

void extract_exit(room_vnum room, int dir)
{
 if (world[room].dir_option[dir]->general_description)
  free(world[room].dir_option[dir]->general_description);
 if (world[room].dir_option[dir]->keyword)
  free(world[room].dir_option[dir]->keyword);
 free(world[room].dir_option[dir]);
}

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST