Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ help needed

help needed

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


Pages: 1 2  

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Sat 30 Jun 2007 05:21 AM (UTC)
Message
gdb ./smaug ../area/core
GNU gdb 5.3
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-slackware-linux"...
Core was generated by `smaug 1202 hotboot 8'.
Program terminated with signal 11, Segmentation fault.

warning: current_sos: Can't read pathname for load map: Input/output error

Cannot access memory at address 0x4c4c5255
#0 0x2283b892 in ?? ()
(gdb) bt
#0 0x2283b892 in ?? ()
#1 0x080e2279 in nextLetter (row=1, col=1, num=21) at scrabble.c:421
#2 0x080e1d93 in nextLetter (row=2, col=1, num=20) at scrabble.c:336
#3 0x080e1d93 in nextLetter (row=3, col=1, num=19) at scrabble.c:336
#4 0x080e1d93 in nextLetter (row=4, col=1, num=18) at scrabble.c:336
#5 0x080e2369 in nextLetter (row=4, col=2, num=17) at scrabble.c:438
#6 0x080e217a in nextLetter (row=3, col=2, num=16) at scrabble.c:404
#7 0x080e217a in nextLetter (row=2, col=2, num=15) at scrabble.c:404
#8 0x080e2279 in nextLetter (row=1, col=3, num=14) at scrabble.c:421
#9 0x080e1d93 in nextLetter (row=2, col=3, num=13) at scrabble.c:336
#10 0x080e1d93 in nextLetter (row=3, col=3, num=12) at scrabble.c:336
#11 0x080e1d93 in nextLetter (row=4, col=3, num=11) at scrabble.c:336
#12 0x080e2369 in nextLetter (row=4, col=4, num=10) at scrabble.c:438
#13 0x080e217a in nextLetter (row=3, col=4, num=9) at scrabble.c:404
#14 0x080e217a in nextLetter (row=2, col=4, num=8) at scrabble.c:404
#15 0x080e217a in nextLetter (row=1, col=4, num=7) at scrabble.c:404
#16 0x080e217a in nextLetter (row=0, col=4, num=6) at scrabble.c:404
#17 0x080e1f85 in nextLetter (row=0, col=3, num=5) at scrabble.c:370
#18 0x080e1f85 in nextLetter (row=0, col=2, num=4) at scrabble.c:370
#19 0x080e1d93 in nextLetter (row=1, col=2, num=3) at scrabble.c:336
#20 0x080e2087 in nextLetter (row=0, col=1, num=1) at scrabble.c:387
#21 0x080e194f in startWord (row=0, col=0, num=1) at scrabble.c:237
#22 0x081941a1 in do_scrabble (ch=0x8e2e880, argument=0x0) at scrabble.c:154
#23 0x080b1502 in interpret (ch=0x8e2e880, argument=0x5e9843c9 "showwords") at interp.c:611
#24 0x080710d6 in game_loop () at comm.c:881
#25 0x080705e7 in main (argc=4, argv=0x5e9868d4) at comm.c:440
#26 0x227d6d06 in ?? ()
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #1 on Sat 30 Jun 2007 05:32 AM (UTC)
Message
sorry had to break it up:

Scrabble Blast v1.0

1 2 3 4 5
-----------
1 | R U L L D
2 | I P R N O
3 | I O A D U
4 | O M J F Z
5 | O H C F X

Syntax: scrabble <word>
scrabble choose <word> <word #>
scrabble set <row> <col> <letter>
scrabble showwords

Alrighty I made a small little scrabble game for my mud, everything compiled fine, no errors or warnings. But when i run the showwords part of my function, the mud crashes. The part that is bugging me is it is crashing in different places each time. i already checked and made sure i made clean and recompiled, but still the same results. i tried searching google for the wierd warning i got since it was the first time id seen it.

http://www.mudbytes.net/index.php?a=pastebin&s=view&pid=1693

i pasted scrabble.c into mudbytes for your viewing pleasure
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #2 on Sat 30 Jun 2007 06:08 AM (UTC)
Message
What you're seeing is very typical of stack overflow. I'd run it through Valgrind -- that's the quickest way to find the problem. If you can't use Valgrind, use asserts to sanity-check all arguments to functions.

Also note that strings need to be long enough to have the zero bytes.

On a more general note:
I'm not sure I understand the design of your scrabble program. If the variables are all global, does that mean only one game can be played at a time?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #3 on Sat 30 Jun 2007 07:21 AM (UTC)
Message
well i went through and created something that should have been in there in the first place, which was a check along every step of the way to make sure we are creating a word, since there is no point going all the way to 7 letters if no word in the dictionary starts with the first 2-3-4-5etc letters. doing that was able to stop the crashing. however now i am getting a memory leak. and i can't figure out why.
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #4 on Sat 30 Jun 2007 07:22 AM (UTC)
Message
oh and the variables will eventually be transferred into the char struct so each player can have their own game.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #5 on Sat 30 Jun 2007 07:25 AM (UTC)
Message
Well, again, the best way to figure out the memory leak is to run this through Valgrind. Sure beats poring through the code by hand, especially when you know how to trigger the memory leak.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #6 on Sat 30 Jun 2007 07:33 AM (UTC)
Message
yeah i know perfectly how to trigger it, unfortunately wolfpaw is run by i am guessing lazy bums, since i wrote them many messages asking them to install valgrind but never got any response. i figured out the problem, somehow the words are growing larger than 7 letters long, even though i put a check in to prevent that:

if ( strlen(sofar) > 6 )
return;
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #7 on Sat 30 Jun 2007 07:39 AM (UTC)
Message
Can you install it into your own directory by any chance? Looking at this page:
http://valgrind.org/docs/manual/manual-core.html#manual-core.install
it doesn't look that hard to do.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #8 on Sat 30 Jun 2007 07:55 AM (UTC)
Message
I am a bit confused about the code you showed. For one thing, I gather each position is a single letter? So why do STRALLOC for each position in the array? Why not have an array of char (not char *) and simply store the character in each position? Ones not set could simply be zero.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #9 on Sat 30 Jun 2007 08:20 AM (UTC)
Message
from what i remember i was unable to install valgrind, so i had asked wolfpaw if they could do it, but they never responded to my emails, how nice of them huh.
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #10 on Sat 07 Jul 2007 08:27 AM (UTC)
Message
ok was able to get onto a friends server with valgrind and fire it up, i then triggered the function and well i got a lot of stuff that i am trying to sort through, any help would be appreciated:

http://www.mudbytes.net/index.php?a=pastebin&s=view&pid=1743

the part initiated by scrabble starts at line 335
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #11 on Sat 07 Jul 2007 10:52 AM (UTC)
Message
This is the sort of thing that the Lua interface would help with. String handling is much easier, and it virtually never crashes. You don't need to change the character structure, and it keeps an instance per player.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #12 on Sat 07 Jul 2007 10:08 PM (UTC)
Message
alright i tried fixing this but i cant seem to get it to work correctly. i googled "Invalid write of size 1" and it said something about going outside an arrays range. i put in checks to make sure they were not outside the range, but it still said the same thing.


    if ( num < 0 || num >= 2000 || row < 0 || col < 0 || row > 4 || col > 4 )
        return;

    strcat( curword[num], scrabble[row][col] );


now after putting in these checks, i did notice a vast improvement in the speed as well as a glitch or two disappeared, but apparently it still needs work.
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #13 on Sat 07 Jul 2007 10:28 PM (UTC)
Message
yes it definitely still needs help, while the glitch where the strings extended past 7 letters was fixed, however the memory is still being corrupted and affecting other areas, prompts are being changed to a random word that was used, etc.
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #14 on Sat 07 Jul 2007 11:55 PM (UTC)

Amended on Sat 07 Jul 2007 11:58 PM (UTC) by Gohan_TheDragonball

Message
any idea why this is not working as it should?

sprintf(sql,"select * from dictionary where word like '%s%%'", word );
bug ( sql );

Sat Jul 7 08:42:45 PM 2007 :: (db.c, line 4976) :: [*****] BUG: select * from dictionary where word like 'OL

for some reason its cutting off instead of putting a percent sign in there as well as the last single quote.
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.


62,364 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

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