Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95

    In Need of some serious help debugging


    Well i've been busting my *** for the last week or so to make my first program with some form of AI. It's a tictacto game. i have coded teh entire thing, and i can run it for a couple moves, then it craps out. I've been debugging it for a day or so now, and i've managed to isolate where the problem is i think. i am h aving access violations but i dont understand why!!! i didnt think that i was trying to access any members that were private. anyways, i just cant look at this code anymore, its all starting to look the same, so i was hoping a fresh set of eyes would help. that and the fact that most u guys seem really smart u'll prolly see what's wrong in a minute or two!:D
    It's a lot of code, so i understand if nobody has the time to look thru it, but if u want to give me a hand, here is the link to d/l it. it's in MSvisual studio 6 and its packed into an RAR file, it is not an EXE, it is an ARCHIVE.d/l here

    PS. very important if u do take a look at this, only look at the code for the Easy Game Play Engine. In an attempt to make debuggin ezier im just trying to get that one to work first.
    Last edited by infamous41md; March 23rd, 2003 at 09:00 PM.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    It'll probably be a few days before I could look at the code (extremely busy time for me), so I'll toss out a couple thoughts that might get you looking at the code a bit differently. I've been in the same situation of banging my head against code that doesn't work, but when I start looking at it from a different perspective the bug usually jumps out at me. Or as the old truism goes:
    There are only two kinds of bugs: subtle ones and obvious ones.
    A subtle bug is one that you haven't found yet. Then when you do find it, it instantly becomes an obvious bug.

    I don't think that it's an issue with trying to access private properties, because, as I recall, the compiler catches those, so they wouldn't show up at run-time.

    If you are using pointers, then you might be using an uninitialized pointer or trying to access an object that has been deleted and no longer exists.
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Another thought hit me while I was waking up this morning.

    Is this a Windows app? There's a sequence to creating and destroying a window, such as a dialog box -- I'd have to pull out my note from a couple years ago to give you that sequence. If you try to access certain things in that window object either before it has been initialized or after it has been closed/destroyed (I forget that part of the sequence now), then you will get a runtime error which, as I recall, refers to an access error.

    You should use the debug facility of Visual Studio 6. When you get the error message box, pick the debug option. Even though it dumps you deep into its unrecognizable code (or even assembly code), you can use the Call Stack (look at the multiple-tab stuff in the bottom of the screen) to trace back through all the function calls back to which function of yours had triggered the crash. Look at the variable values displayed there. You should see a pointer with a NULL value in it or a HWnd variable with an invalid value or a bogus array index or something that is not right.

    If you're still not sure what's wrong, then put a breakpoint just before the first possibly suspect line in the function in question start the debugger with a "Go To" that will run the program until it hits the breakpoint. Then you can step through until you hit the offending statement. There are two ways to single-step through: Step Into will follow a function call into the called function, while Step Over will call the function and then step to the next statement. Use Step Over until you've identified the offending statement, then , if you still don't understand what's wrong, you can rerun the debug up to that point again and this time Step Into the offending statement.

    Keep an eye on the variable values displayed below while you are single-stepping. It's been a while, but I recall a Watch page attached to one of the tabs on the bottom.


    BTW, WinZIP cannot recognize your file's format. I assumed that your reference to "rar" was a typo and that you had meant "tar".
  6. #4
  7. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    dwise<< thanks for taking the time to help out. to answer the ezier question first, i packed it up in winRAR, it's a self extracting exe, all u have to do is double click it and it will extract to wherever u choose, no need for winzip. now for the hard stuff: i have alread tried setting breakpoints and looking at the call stack. i have been able to isolate the exact point where the access violation occurs, i am just unsure of why it is crashing. if u do get a chance to run it, it will bring u to my linked list class to a function that simply tries to return a value stored in a node, but for some reason it is an "Access Violation".
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Still, I won't be able to take a look at the code until late Monday night or more likely Tuesday night.

    In the meantime, it still sounds like an uninitialized pointer is the cause. It's been a while (in our work with embedded C, our policy is to not use dynamic data structures), but I remember that using a linked list could be tricky and that I had to be mindful of my pointers at all times.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    infamous41md,

    I think most people aren't going to be willing to download a .exe file from an unkown person. The potential for malicious mischief isn't worth it. Some people post links to code they post on their web sites, and that's a whole different thing.

    I suggest you distill the problem down to a few lines of code. Try to replicate the problem with some generic code and then post it here. Also, post the error and the line where it occurred.
  12. #7
  13. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    dwise<< no rush what so ever, i was just commenting back to ur response. i greatly appreciate any help from anyone and totally understand people have busy lives of their own, so no worries about that:) also, when u do get get teh chance, i have made some major adjustments that make it much more readable, tho i am still getting the same errors, i greatly reduced the amount of code. I will change the above link so u can d/l my newer version.

    7stud<< hmm, i guess ur right, i didnt really think about that. i am reuploading a non-exe version to my site, so people can d/l that one instead and do a scan if they wish. Meanwhile, here is the small section of the code that is giving me the problem.

    PHP Code:
    bool cList::inList(int array[], int numElems)
    {
        if(
    isEmpty())
            return 
    false;

        
    bool xflag falseyflag false;
        
        
    cNode *tmp NULL;
        
    tmp = list;

        while(
    tmp->next != NULL)  //right here is the violation, it wont let tmp access next pointer of the node list is pointing to
        
    {
            for(
    int x 0numElemsx++)
            {
                if(array[
    x] == tmp->x)
                    
    xflag true;
                if(array[
    x] == tmp->y)
                    
    yflag true;
            }
            if((
    xflag == true)&&(yflag == true))
                return 
    true;
            else
                
    tmp tmp->nextxflag falseyflag false;
        }

        for(
    int y 0numElemsy++)
            {
                if(array[
    y] == tmp->x)
                    
    xflag true;
                if(array[
    y] == tmp->y)
                    
    yflag true;
            }
            if((
    xflag == true)&&(yflag == true))
                return 
    true;
            else
                return 
    false;

    Last edited by infamous41md; March 23rd, 2003 at 03:47 PM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    "Also, post the error".

    There are two things most people are going to want to see everytime you want help: the actual error message(sometimes it's clear what the error is just from the message), and the line number.

    Your problem might be here:

    tmp = list;

    Is there a member variable called "list"? What's in list?
    Last edited by 7stud; March 23rd, 2003 at 05:22 PM.
  16. #9
  17. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    there is no "real" error. its not syntax, its logic. and list is a private member of the cList class, its a pointer to the first node in the list, im seeing that wasnt inherently obvious from the code i posted, but i didnt want to post 3 pages of code.
    Last edited by infamous41md; March 23rd, 2003 at 05:23 PM.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Sorry, I realized that and was changing my post when you replied.

    I would guess there's no next pointer for the object list is pointing to at some point. Maybe the end?
  20. #11
  21. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    yea , that's what i dont understand. i know that im creating the list correctly, so i dont understand why it cant access the next pointer of the node. its almost like the node is not even there. here i will post how i created the list, maybe u can see an error in that that i am blind to:

    PHP Code:
    cNode *ptr = new cNode(3,6);            //fill list array with moves to block a win
        
    cNode *ptr2 = new cNode(4,8);
        
    cNode *ptr3 = new cNode(1,2);
        
    listArray[0]->addToHead(ptr);
        
    listArray[0]->addToHead(ptr2);
        
    listArray[0]->addToHead(ptr3);
        
    ptr = new cNode(0,2);
        
    ptr2 = new cNode(4,7);
        
    listArray[1]->addToHead(ptr);
        
    listArray[1]->addToHead(ptr2);
        
    ptr = new cNode(0,1);
        
    ptr2 = new cNode(4,6);
        
    ptr3 = new cNode(5,8);
        
    listArray[2]->addToHead(ptr);
        
    listArray[2]->addToHead(ptr2);
        
    listArray[2]->addToHead(ptr3); 
    listArray is an array of pointers to linked lists, this is how i initialize it:

    PHP Code:
    for(int m 09m++)
                    
    listArray[m] = new cList();} 
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Can you post the cList class definition?
  24. #13
  25. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    surely:

    PHP Code:
    #include "LinkedList.h"
    #include<iostream.h>

    cNode::cNode(int x1int y1)
    {
        
    next NULL;
        
    x1;
        
    y1;    
    }


    // class cList

    cList::cList()
    {
        list = 
    NULL;
    }

    void cList::addToHead(cNode *node)
    {    
        if(list == 
    NULL)
        {
            list = 
    node;
            
    delete node;
        }
        else
        {
            
    node->next = list;
            list = 
    node;
            
    delete node;
        }
        
    }

    void cList::addToTail(cNode *node)

        
    cNode *temp = list;
        
    cout << list << "\n";
        
    cin.ignore();
        
    cout << temp << "\n";
        
    cin.ignore();
        while(
    temp != NULL)
        {
            
    temp temp->next;
        }
        
    temp->next node;
        
    temp NULL;
    }

    bool cList::delFromHead()
    {
        if(list != 
    NULL)
        {
        
    cNode *temp = list;
        list = list->
    next;
        
    temp->next NULL;
        
    temp NULL;
        return 
    true;
        }
        else
            return 
    false;
    }

    bool cList::delFromTail()
    {
        
    int x 0;

        if((list!=
    NULL)&&(list->next != NULL))
        {
        
    cNode *temp = list;
        while(
    temp->next != NULL)
        {
            
    temp temp->next;
            
    x++;
        }
        
    cNode *temp2 = list;
        for(
    int y 1xy++)
            
    temp2 temp2->next;
        
    temp2->next NULL;
        
    temp NULL;
        return 
    true;
        }
        else
            return 
    false;
    }

    bool cList::isEmpty()
    {
        if (list == 
    NULL)
            return 
    true;
        else 
            return 
    false;
    }

    bool cList::inList(int array[], int numElems)
    {
        if(
    isEmpty())
            return 
    false;

        
    bool xflag falseyflag false;
        
        
    cNode *tmp NULL;
        
    tmp = list;

        while(
    tmp->next != NULL)
        {
            for(
    int x 0numElemsx++)
            {
                if(array[
    x] == tmp->x)
                    
    xflag true;
                if(array[
    x] == tmp->y)
                    
    yflag true;
            }
            if((
    xflag == true)&&(yflag == true))
                return 
    true;
            else
                
    tmp tmp->nextxflag falseyflag false;
        }

        for(
    int y 0numElemsy++)
            {
                if(array[
    y] == tmp->x)
                    
    xflag true;
                if(array[
    y] == tmp->y)
                    
    yflag true;
            }
        if((
    xflag == true)&&(yflag == true))
            return 
    true;
        else
            return 
    false;

  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Sorry, you posted the definitions of the cList functions, which may be helpful later, but for now I would like to see the class definition: the part that declares the members and functions of cList.
  28. #15
  29. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    heh, my bad sorry:

    PHP Code:
    #ifndef _LINKEDLIST_H_
    #define _LINKEDLIST_H_

    class cNode {
        
    friend class cList;
    private:
        
    int x;
        
    int y;
        
    cNode *next;
    public:
        
    cNode(int x1int y1);
    };

    class 
    cList {
    private:
        
    cNode *list;

    public:
        
    cList();
        
    void addToHead(cNode *node);
        
    void addToTail(cNode *node);
        
    bool delFromHead();
        
    bool delFromTail();
        
    bool isEmpty();
        
    bool inList(int array[], int numElems);
        
    void print();
        
    };
    #endif 
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo