The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
In Need of some serious help debugging
Discuss In Need of some serious help debugging in the C Programming forum on Dev Shed. In Need of some serious help debugging C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 22nd, 2003, 06:46 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
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!
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.
|

March 23rd, 2003, 12:54 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
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.
|

March 23rd, 2003, 09:23 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
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".
|

March 23rd, 2003, 01:14 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
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".
|

March 23rd, 2003, 01:41 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
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.
|

March 23rd, 2003, 03:03 PM
|
|
Contributing User
|
|
Join Date: Feb 2001
Posts: 1,365

Time spent in forums: 18 h 9 m 25 sec
Reputation Power: 14
|
|
|
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.
|

March 23rd, 2003, 03:44 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
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 = false, yflag = 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 = 0; x < numElems; x++)
{
if(array[x] == tmp->x)
xflag = true;
if(array[x] == tmp->y)
yflag = true;
}
if((xflag == true)&&(yflag == true))
return true;
else
tmp = tmp->next; xflag = false; yflag = false;
}
for(int y = 0; y < numElems; y++)
{
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.
|

March 23rd, 2003, 05:16 PM
|
|
Contributing User
|
|
Join Date: Feb 2001
Posts: 1,365

Time spent in forums: 18 h 9 m 25 sec
Reputation Power: 14
|
|
|
"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.
|

March 23rd, 2003, 05:21 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
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.
|

March 23rd, 2003, 05:25 PM
|
|
Contributing User
|
|
Join Date: Feb 2001
Posts: 1,365

Time spent in forums: 18 h 9 m 25 sec
Reputation Power: 14
|
|
|
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?
|

March 23rd, 2003, 05:30 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
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 = 0; m < 9; m++)
listArray[m] = new cList();}
|

March 23rd, 2003, 05:35 PM
|
|
Contributing User
|
|
Join Date: Feb 2001
Posts: 1,365

Time spent in forums: 18 h 9 m 25 sec
Reputation Power: 14
|
|
|
Can you post the cList class definition?
|

March 23rd, 2003, 05:42 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
surely:
PHP Code:
#include "LinkedList.h"
#include<iostream.h>
cNode::cNode(int x1, int y1)
{
next = NULL;
x = x1;
y = 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 = 1; y < x; y++)
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 = false, yflag = false;
cNode *tmp = NULL;
tmp = list;
while(tmp->next != NULL)
{
for(int x = 0; x < numElems; x++)
{
if(array[x] == tmp->x)
xflag = true;
if(array[x] == tmp->y)
yflag = true;
}
if((xflag == true)&&(yflag == true))
return true;
else
tmp = tmp->next; xflag = false; yflag = false;
}
for(int y = 0; y < numElems; y++)
{
if(array[y] == tmp->x)
xflag = true;
if(array[y] == tmp->y)
yflag = true;
}
if((xflag == true)&&(yflag == true))
return true;
else
return false;
}
|

March 23rd, 2003, 05:48 PM
|
|
Contributing User
|
|
Join Date: Feb 2001
Posts: 1,365

Time spent in forums: 18 h 9 m 25 sec
Reputation Power: 14
|
|
|
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.
|

March 23rd, 2003, 05:49 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
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 x1, int 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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|