Thread: Rouge Segmentation Fault, can't be found...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    4

    Rouge Segmentation Fault, can't be found...

    I need a little bit of help: I'm writing a program in Linux that is a network-enabled poker game. Problem is, everytime I try to run it, I get a segmentation fault. I can't ID it, and I have MORE than enough debug statements. If you'd like to take a look at my code and try to find it, please do.

    http://pmw.myip.org/~cn3/deck.cpp
    http://pmw.myip.org/~cn3/game.cpp
    http://pmw.myip.org/~cn3/oneplay.cpp
    http://pmw.myip.org/~cn3/player.cpp
    http://pmw.myip.org/~cn3/credits.cpp

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Geeze Salem...use code tags!
    Away.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    4
    Originally posted by Salem
    holder=new Player(getname, getpass, getcoins, 0);
    users[x]=*holder;
    }
    delete holder;
    You call new in a loop, and only call delete once....
    Alright, I see that. Fixed.
    Originally posted by Salem
    Card *temp;
    temp=deck[a];
    deck[a]=deck[b];
    deck[b]=temp;
    delete temp;
    You call delete without calling new
    Fixed, too.

    Originally posted by Salem
    > Card *deck[52];
    Card deck[52];
    seems to be a lot simpler to me. It would save a lot of worrying about matching up new/delete calls.
    Well, the reason I do that is so that I can swap cards and stuff. Would it work if they're not pointers?

    Originally posted by Salem
    These are just some suggestions


    case 0: n=1;
    break;
    case 1: n=2;
    break;
    case 2: n=3;
    break;
    .....
    How about
    n = (x%13)+1;


    case 0: s='H';
    break;
    case 1: s='D';
    break;
    .....
    And
    s = "HDCS"[x/13];
    ^_^; I feel REALLY stupid right about now, thanks for that... But, can you access elements of a string constant like that? If so, I need to go revise some old programs... *runs off at speed of brick*


    EDIT: AAACKKK!!! IT'S STILL THERE!!! *pulls out what little hair he has left* WHY?!?!?
    Last edited by Flamora; 05-14-2003 at 09:42 AM.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    4
    Well, this is what I get from gdb:

    Program received signal SIGSEGV, Segmentation fault.
    0x4016066e in chunk_free () from /lib/libc.so.6


    ?!?

    ltrace gives me this...

    _ZNSolsEi(0x0804ed10, 0, 0xbffff6c8, 0x0804acb2, 0xbffff5d0 <unfinished ...>
    --- SIGSEGV (Segmentation fault) ---
    +++ killed by SIGSEGV +++


    WTF?

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    4
    *sigh* Has EVERYONE forgotten my program?!? Because, that **** segmentation fault is STILL THERE... -_-; And the program is due... *looks at calender* Friday?!? *sigh*

  6. #6
    Cat
    Guest
    Well, does your program even get to a point where you're asking for input?

    Narrow down where you're segfaulting. Heck, in every function, print an "Entering function _____" as the first line of the function, and an "Leaving function _______" as the last before the return (and flush the output buffers after each). That will narrow the segfault down to a much tinier area of code.

    Segmentation faults are *almost* always caused by using a pointer that doesn't point to anything, so check your pointers first. Pay attention to any compiler warnings (especially "xxx may be used before initialization" type warnings).

    And, as Salem said, put the newest version of your code up.

  7. #7
    Registered User HaLCy0n's Avatar
    Join Date
    Mar 2003
    Posts
    77
    Looking at it quickly, it looks like your problem is in your destructor for Hand. You are deleting cards, and if I'm looking at it right, cards looks like it would be an array of pointers, not a pointer to an array. You can't delete a static array like that. You have to loop through and delete each element.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault problem
    By odedbobi in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2008, 03:36 AM
  2. Why am I getting segmentation fault on this?
    By arya6000 in forum C++ Programming
    Replies: 6
    Last Post: 10-12-2008, 06:32 AM
  3. segmentation fault... first time with unix...
    By theMethod in forum C Programming
    Replies: 16
    Last Post: 09-30-2008, 02:01 AM
  4. Re: Segmentation fault
    By turkish_van in forum C Programming
    Replies: 8
    Last Post: 01-20-2007, 05:50 PM
  5. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM