[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Crash in mprog_speech_trigger

Crash in mprog_speech_trigger

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Samson   USA  (683 posts)  [Biography] bio
Date Fri 05 Aug 2005 03:37 AM (UTC)
Message
The code:


void mprog_speech_trigger( char *txt, char_data * actor )
{
   char_data *vmob;
   list<char_data*>::iterator ich;
   room_index *room = actor->in_room;

   log_string( "HERE I AM" );
   for( ich = room->people.begin(); ich != room->people.end(); )
   {
      vmob = (*ich);
      ich++;

      log_printf( "THIS IS ROOM: %d", room->vnum );
      log_printf( "MY NAME IS: %s", vmob->name );
      log_printf( "TEXT: %s", txt );
      if( vmob->isnpc(  ) && HAS_PROG( vmob->pIndexData, SPEECH_PROG ) )
      {
         if( actor->isnpc(  ) && actor->pIndexData == vmob->pIndexData )
            continue;
         mprog_wordlist_check( txt, vmob, actor, NULL, NULL, SPEECH_PROG );
      }
   }
}


The mobprog:


>speech_prog p I am ready
if mobinroom(2868) == 1
mpecho The statue of Meia glows with a blue aura and animates.
say You are not yet ready to receive your reward and leave.
say Defeat the Guardian first.
mpecho The aura around the statue disappears and it is still again.
else
mpecho The statue of Meia glows with a blue aura and animates.
say You are now ready to leave the safety of Gwyn al'Fer.
say Fare thee well in your adventures in Alsherok.
give runed $n
say Take this as a reward and may it serve you well.
mpecho The aura around the statue disappears and it is still again.
mpecho You are drawn through a magical portal which opens before you.
mpopenpassage 2926 7035 4
mpforce $n up
mpclosepassage 2926 4
endif


What I caught in debugging:


Thu Aug 4, 2005 8:22:21 PM PDT :: Loading player data for Samson (37K)
Thu Aug 4, 2005 8:22:21 PM PDT :: Samson [samson.arthmoor.com] has connected.
Thu Aug 4, 2005 8:22:24 PM PDT :: MCCP support detected for Samson.
Thu Aug 4, 2005 8:22:24 PM PDT :: MSP support detected for Samson.
Thu Aug 4, 2005 8:22:24 PM PDT :: Samson returns from beyond the void.
Thu Aug 4, 2005 8:22:27 PM PDT :: HERE I AM
Thu Aug 4, 2005 8:22:27 PM PDT :: THIS IS ROOM: 2926
Thu Aug 4, 2005 8:22:27 PM PDT :: MY NAME IS: statue meia carving abecedarium
Thu Aug 4, 2005 8:22:27 PM PDT :: TEXT: i am ready
Thu Aug 4, 2005 8:22:27 PM PDT :: HERE I AM
Thu Aug 4, 2005 8:22:27 PM PDT :: THIS IS ROOM: 2926
Thu Aug 4, 2005 8:22:27 PM PDT :: MY NAME IS: statue meia carving abecedarium
Thu Aug 4, 2005 8:22:27 PM PDT :: TEXT: You are now ready to leave the safety of Gwyn al'Fer.
Thu Aug 4, 2005 8:22:27 PM PDT :: THIS IS ROOM: 2926
Thu Aug 4, 2005 8:22:27 PM PDT :: MY NAME IS: Samson
Thu Aug 4, 2005 8:22:27 PM PDT :: TEXT: You are now ready to leave the safety of Gwyn al'Fer.
Thu Aug 4, 2005 8:22:27 PM PDT :: HERE I AM
Thu Aug 4, 2005 8:22:27 PM PDT :: THIS IS ROOM: 2926
Thu Aug 4, 2005 8:22:27 PM PDT :: MY NAME IS: statue meia carving abecedarium
Thu Aug 4, 2005 8:22:27 PM PDT :: TEXT: Fare thee well in your adventures in Alsherok.
Thu Aug 4, 2005 8:22:27 PM PDT :: THIS IS ROOM: 2926
Thu Aug 4, 2005 8:22:27 PM PDT :: MY NAME IS: Samson
Thu Aug 4, 2005 8:22:27 PM PDT :: TEXT: Fare thee well in your adventures in Alsherok.
Thu Aug 4, 2005 8:22:27 PM PDT :: HERE I AM
Thu Aug 4, 2005 8:22:27 PM PDT :: THIS IS ROOM: 2926
Thu Aug 4, 2005 8:22:27 PM PDT :: MY NAME IS: statue meia carving abecedarium
Thu Aug 4, 2005 8:22:27 PM PDT :: TEXT: Take this as a reward and may it serve you well.
Thu Aug 4, 2005 8:22:27 PM PDT :: THIS IS ROOM: 2926
Thu Aug 4, 2005 8:22:27 PM PDT :: MY NAME IS: Samson
Thu Aug 4, 2005 8:22:27 PM PDT :: TEXT: Take this as a reward and may it serve you well.
Thu Aug 4, 2005 8:22:27 PM PDT :: THIS IS ROOM: 2926
==27643== 
==27643== Invalid read of size 1
==27643==    at 0x1D172F: vfprintf (in /lib/libc-2.3.5.so)
==27643==    by 0x1EF76E: vsnprintf (in /lib/libc-2.3.5.so)
==27643==    by 0x8153C86: log_printf(char const*, ...) (db.c:2560)
==27643==    by 0x81AAF93: mprog_speech_trigger(char*, char_data*) (mud_prog.c:3500)
==27643==    by 0x80D8EC0: do_say (act_comm.c:500)
==27643==    by 0x814E6D7: interpret(char_data*, char*) (commands.c:1427)
==27643==    by 0x81486AB: process_input() (comm.c:824)
==27643==    by 0x814873A: game_loop() (comm.c:890)
==27643==    by 0x8148A24: main (comm.c:1258)
==27643==  Address 0x6 is not stack'd, malloc'd or (recently) free'd
==27643== 
==27643== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- 


There are only two characters in room 2926. Myself and the mob Meia. This is a consistent crasher in this one function apparently. I have no idea why, and indications are that the room's list of people picked up something it wasn't supposed to as it got to the last say command in the prog, even though of course no other characters entered or left the room. Any ideas on what I can do now?
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #1 on Fri 05 Aug 2005 05:15 AM (UTC)
Message
The only thing that springs to mind is that ich may be valid, but dereferenced it is corrupt. I'm not sure, but can you reproduce it in GDB? Is *ich valid? What if you just print room->people.end() and *room->people.end()? Something to try.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Reply #2 on Fri 05 Aug 2005 12:15 PM (UTC)

Amended on Fri 05 Aug 2005 12:21 PM (UTC) by Samson

Message

(gdb) frame 3
#3  0x081aaf94 in mprog_speech_trigger (txt=0xbfccf038 "I am ready", actor=0x9478420) at mud_prog.c:3500
3500          log_printf( "MY NAME IS: %s", vmob->name );
(gdb) info locals
vmob = (char_data *) 0x93a4b78
room = (room_index *) 0x936c558
(gdb) info args
txt = 0xbfccf038 "I am ready"
actor = (char_data *) 0x9478420
(gdb) print vmob
$4 = (char_data *) 0x93a4b78
(gdb) print vmob->name
$5 = 0x6d65540d <Address 0x6d65540d out of bounds>
(gdb)


When I tried to do "print room->people.end()" the program resumed operating after calling the alarm signal handler. I got transferred to the new room even, so the prog did complete - but this is of course with the debugger in control. When I went back and triggered it again, GDB had this to say when it segfaulted again:

Quote:

Program received signal SIGSEGV, Segmentation fault.
0x0032772f in vfprintf () from /lib/libc.so.6
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (std::list<char_data*, std::allocator<char_data*> >::end()) will be abandoned.


So I tried this in frame 3 again:


(gdb) print room->vnum
$7 = 2926
(gdb) print room->people
$8 = {<std::_List_base<char_data*,std::allocator<char_data*> >> = {
    _M_impl = {<std::allocator<std::_List_node<char_data*> >> = {<__gnu_cxx::__mt_alloc<std::_List_node<char_data*>,__gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, true> >> = {<__gnu_cxx::__mt_alloc_base<std::_List_node<char_data*> >> = {<No data fields>}, <No data fields>}, <No data fields>}, _M_node = {
        _M_next = 0x93ca978, _M_prev = 0x93ca978}}}, <No data fields>}
(gdb) print *(room->people.end())
One of the arguments you tried to pass to operator* could not be converted to what the function wants.
(gdb) print *room->people.end()
One of the arguments you tried to pass to operator* could not be converted to what the function wants.


So I'm still as stumped as before. Obviously something is corrupting the room->people list but I cannot figure out what or where.

EDIT: Oh, and it should probably be noted that ich is not showing up on the list of local variables and gdb tells me there is no ich symbol in the current context.
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #3 on Fri 05 Aug 2005 09:44 PM (UTC)
Message
For the record, when I was having problems with my list a few days ago, I tried to pring my iterator as well, and got the same thing, that it didn't exist. Is this something specific to list iterators?

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #4 on Fri 05 Aug 2005 11:32 PM (UTC)
Message
The value "*(room->people.end())" is bogus, since the end of STL containers does not point to the last element but rather to one step beyond the last element. That is why iterating from it = begin() to it != end(), it++, will work - when it==end() you have reached the end of the list because you've gone one step beyond the last valid element.

As to why you're having these other problems, I'm not sure, but this might help you out a little...

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Reply #5 on Sat 06 Aug 2005 07:45 PM (UTC)
Message
Well a bit of progress. On a guess, changed the log_printf that shows what room it is from room->vnum to actor->in_room->vnum and found out that the room was being changed to 7035 *BEFORE* the actual command to move the person had been executed (?!?). So I came up with a temporary band-aid:


void mprog_speech_trigger( char *txt, char_data * actor )
{
   char_data *vmob;
   list<char_data*>::iterator ich;
   room_index *room = actor->in_room;

   log_string( "HERE I AM" );
   for( ich = room->people.begin(); ich != room->people.end(); )
   {
      vmob = (*ich);
      ich++;

      if( actor == vmob )
         continue;
      if( actor->isnpc(  ) && actor->pIndexData == vmob->pIndexData )
         continue;

      // Band-aid fix to stop unknown crash
      if( actor->in_room != vmob->in_room )
         break;

      log_printf( "THIS IS ROOM: %d", actor->in_room->vnum );      
      log_printf( "MY NAME IS: %s", vmob->name );
      log_printf( "TEXT: %s", txt );
      if( vmob->isnpc(  ) && HAS_PROG( vmob->pIndexData, SPEECH_PROG ) )
      {
         mprog_wordlist_check( txt, vmob, actor, NULL, NULL, SPEECH_PROG );
      }
   }
}


With that band-aid in place it will at least not crash. But I am wondering if it would be an adequate permanent fix. the only problem I see is if you want to trigger a speech prog on a mob in a different room from the actor. But how often is this really done? Is it even desirable to have tells able to do this?
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #6 on Sun 07 Aug 2005 10:24 PM (UTC)
Message
Here's a thought: Does mprog_wordlist_check() move the character to another room? If so, when being moved are you calling something like room->people.erase(ich)? If so, this would corrupt the list, and you could not use it from there on. You would have to reset ich back to room->people.begin(), or iterate over a copy instead. I dunno if this is the case, but it could certainly cause this problem.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #7 on Mon 08 Aug 2005 12:49 PM (UTC)
Message
Refering to why there seems to be problems getting GDB to recognize some variables as valid information to print, I, apparently, asked this same question a year ago, and totally forgot.
Quote:
This puzzles me. You are debugging a .c file but it says the language is c++. This might cause confusion because of C++ name mangling.

Maybe type "set language c" and try again.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


20,135 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]