Re: [NEWBIE][CODE][LONG] Mud Crashing - Errors possibly with heartbeat?

From: Thomas Arp (t_arp@stofanet.dk)
Date: 01/31/03


From: "Josh Harris" <jharris2@ACSU.BUFFALO.EDU>
> then for my check_evil() function I put it in weather.c just because
> that's where the function I was referencing it from was at.
>
>
> void check_evil() {
> struct descriptor_data *d;
>
> for (d = descriptor_list; d; d = d->next)
>     if (d->connected) continue;
>
> send_to_char(d->character, "The evil grows stronger within you.\r\n");
> }
>
> This was just a test code to make sure I had everything set up correctly
> so far.  However I ran my mud, and used set evil on to turn my affections
> flag on and my mud crashed a minute or two later.  When I ran it as
> bin/circle it said core dump and segmentation fault when the mud crashed.
>
Another time, try running gdb on the core (gdb bin/circle lib/core), and
do a backtrace (bt). it will tell you which line caused the crash.

In this case, the problem isn't finding the line. The loop above will
only exit if d is NULL. and _then_ you go ahead and dereference it
right away! You might have been planning something like this instead:

void check_evil(void) {
struct descriptor_data *d;

  for (d = descriptor_list; d; d = d->next) {   }  /* << note the { */
    if (STATE(d) != CON_PLAYING)
      continue;
    if (!d->character) /* just to make sure */
      continue;

    send_to_char(d->character, "The evil grows stronger within you.\r\n");
  }  /* << note the } */
}
Which will send the message to all characters online, regardless if they're
paging, deaf, etc.

Welcor

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/26/03 PDT