void execute_char_event(CHAR_DATA * ch, EVENT_DATA * event)
{ switch(event->event )
{ case EVENT_PRINT:
send_to_char(event->string,ch);
break;
case EVENT_MOVE:
event_move(ch, NULL, event->string);
break;
default:
LOG("Execute_event: Bad event type" );
break;
}
free_event(ch, NULL, event);
return;
}
valgrind –tool=memcheck ../src/merc
==19521== Memcheck, a memory error detector
==19521== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==19521== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==19521== Command: ../src/merc
==19521==
Sun Aug 15 11:53:05 2010 :: IMC: Loading all the IMC stuff we don't care about
==19521== Syscall param socketcall.setsockopt(optval) points to uninitialised byte(s)
==19521== at 0x40008D2: ??? (in /lib/ld-2.10.1.so)
==19521== by 0x809D57C: main (comm.c:461)
==19521== Address 0xbedc821c is on thread 1's stack
==19521==
Sun Aug 15 11:53:04 2010 :: MOBProgs/407.prg : db.c, 3266
Sun Aug 15 11:53:04 2010 :: MOBProgs/600.prg : db.c, 3266
Sun Aug 15 11:53:04 2010 :: MOBProgs/601.prg : db.c, 3266
Sun Aug 15 11:53:04 2010 :: MOBProgs/602.prg : db.c, 3266
Sun Aug 15 11:53:04 2010 :: MOBProgs/604.prg : db.c, 3266
Sun Aug 15 11:53:04 2010 :: MOBProgs/605.prg : db.c, 3266
Sun Aug 15 11:53:04 2010 :: MOBProgs/606.prg : db.c, 3266
Sun Aug 15 11:53:04 2010 :: MOBProgs/607.prg : db.c, 3266
Sun Aug 15 11:53:04 2010 :: God Wars is ready to rock on port 3040. : comm.c, 466
Sun Aug 15 11:53:07 2010 :: IMC: Standard Authentication completed.
Sun Aug 15 11:53:14 2010 :: Sock.sinaddr: blah : comm.c, 1088
Sun Aug 15 11:53:16 2010 :: Turan trying to connect. : comm.c, 1763
Sun Aug 15 11:53:18 2010 :: Turan@blah has connected. : comm.c, 1899
Sun Aug 15 11:53:25 2010 :: Log Turan: mload 608 : interp.c, 3464
Sun Aug 15 11:53:52 2010 :: Log Turan: resetarea : interp.c, 3464
Sun Aug 15 11:54:27 2010 :: Log Turan: force imp testknock turan east : interp.c, 3464
==19521== Invalid read of size 4
==19521== at 0x809EBC6: alloc_mem (db.c:2664)
==19521== by 0x8070D35: show_list_to_char (act_info.c:277)
==19521== by 0x8071BCB: do_look (act_info.c:1053)
==19521== by 0x80BE531: interpret (interp.c:3547)
==19521== by 0x809D01B: game_loop_unix (comm.c:899)
==19521== by 0x809D5D4: main (comm.c:467)
==19521== Address 0x61727554 is not stack'd, malloc'd or (recently) free'd
==19521==
==19521==
==19521== Process terminating with default action of signal 11 (SIGSEGV)
==19521== Access not within mapped region at address 0x61727554
==19521== at 0x809EBC6: alloc_mem (db.c:2664)
==19521== by 0x8070D35: show_list_to_char (act_info.c:277)
==19521== by 0x8071BCB: do_look (act_info.c:1053)
==19521== by 0x80BE531: interpret (interp.c:3547)
==19521== by 0x809D01B: game_loop_unix (comm.c:899)
==19521== by 0x809D5D4: main (comm.c:467)
==19521== If you believe this happened as a result of a stack
==19521== overflow in your program's main thread (unlikely but
==19521== possible), you can try to increase the size of the
==19521== main thread stack using the –main-stacksize= flag.
==19521== The main thread stack size used in this run was 8388608.
==19521==
==19521== HEAP SUMMARY:
==19521== in use at exit: 2,713,689 bytes in 1,899 blocks
==19521== total heap usage: 2,997 allocs, 1,098 frees, 4,423,117 bytes allocated
==19521==
==19521== LEAK SUMMARY:
==19521== definitely lost: 4 bytes in 4 blocks
==19521== indirectly lost: 0 bytes in 0 blocks
==19521== possibly lost: 131,072 bytes in 1 blocks
==19521== still reachable: 2,582,613 bytes in 1,894 blocks
==19521== suppressed: 0 bytes in 0 blocks
==19521== Rerun with –leak-check=full to see details of leaked memory
==19521==
==19521== For counts of detected and suppressed errors, rerun with: -v
==19521== Use –track-origins=yes to see where uninitialised values come from
==19521== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 21 from 20)
Segmentation fault
if ( rgFreeList[iList] == NULL )
{
pMem = alloc_perm( rgSizeList[iList] );
}
else
{
pMem = rgFreeList[iList];
rgFreeList[iList] = * ((void **) rgFreeList[iList]); // line 2664
}
I recently installed Davion's event handler snippet into my MUD:
Davion's event handler
The basic engine seems to work fine, I can use the included testevent command as often as I like and it works perfectly as expected.
The first event of my own I tried to make is one that will cause a player to move through a series of rooms - I figured this would be useful to make things that can no longer fly fall out of the air, have people uppercutting each other into the sky, smashing folks through rooms, good mayhem. The associated code for all that is here:
Moving event code
The problem is rather specific: Anytime I use testknock to move someone out of the room, it's causing some sort of memory error and segfaulting the MUD (the cores show it crashing in alloc_mem). I can use testknock fine, just so long as the character does not leave the room - that is, if there's no door to the west, I can knock them west and they will correctly slam into the wall and life goes on.
If, however, I knock them east, the command and events will properly execute - they soar off to the east before either hitting a wall or landing, as they should. At some point (could be in the middle of that, could be a few moments later), the MUD will crash. I'm really not sure what I might be doing wrong…the string manipulation inside the movement event is fairly simple, so I don't think I'm borking that, but something is bad in there and I don't see it. Any opinions are gratefully accepted.
P.S. I know there's a way to make the links for the code repository and pastebin have nice description windows, but I don't see a tag for that…