Advertisement

Problem with this code?

Started by August 07, 2000 11:26 PM
28 comments, last by Esap1 24 years, 5 months ago
I checked if every COctree Instance(child) is NULL(0) before I new it, then make sure it not NULL after, and Everythings seems OK. I DONT GET IT, any other steps I should take to debug it?
Now Im really getting Frustrated, how the hell can I debug this and figure out WHAT THE HELL IS WRONG?
Advertisement
it''s a long shot but why don''t you try inserting

if (!this) return; 


at the beginning of your destructor?
[email=ehremo@hotmail.com][/email]
I''ve tried part of the code you posted at home, without the "build", "CVector" and "CBox" stuff (because I don''t have that code), and I had no problems.

Are you sure you''re not doing something like this:
    COctree *oct = new COctree;// Some code...delete oct;// Some more code, without doing a "new" on COctreedelete oct;    


That usually gives an error in the destructor.

And oh yeah, sometimes doing a "full rebuild" might fix it, if you have tinkered with some of your header files .

And if you still can''t fix it, maybe you can make the full code available for download, so we can try it out for ourselves.

Dormeur
Wout "Dormeur" NeirynckThe Delta Quadrant Development Page
remo: I tried if (!this) return; in the top of the Destructor, but It didnt work, though good thinking, I really thought that it might of.


Dormeur:
Actually the Root Octree is not a Pointer. Im just doing this:
class Map {
COctree root;
}


This really sucks, every time I run my game, I lose memory. I need to keep restarting my computer. It seems this just came up. I dont get it.
I am moving this up so people dont think my question has been answered, BECAUSE I STILL HAVE THIS DAMN PROBLEM!
Advertisement
FIrst, try putting the word void in the parenthesis for the deconstructor. I don''t know if it will do anything, but hell, you''re desperate . Second, theres no point in assigning false to isOK since the deconstructor releases the memory, so isOk is non-existant after the deconstructor ends.

=======================================
A man with no head is still a man.
A head with no man is plain freaky.
Zipster: that won''t do anything

Esap: you gotta either post the whole code or debug it yourself. You said you weren''t that good at debugging; well, it''s time to learn. When you get the error, step back in the execution stack and figure out how the destructor is being called. If it''s called from a delete, look at that pointer. If it''s at the end of a function, you''ve got an automatic object (i.e. stack object) being deleted.

Like many here have said, the code you''ve posted here works. The problem is outside of the code you''ve posted. Either you''ve gotta post all the code, or you gotta figure out what other part of your code is causing the problem. I understand your frustration, but understand that we can''t help you with what you''ve given us.

Debugging skill is about 50% of what goes into making a good programmer, so try to look at this as making you a better programmer.

If you need some specific help with running the MSVC (I assume) debugger, I can help you out there.
Here''s some background info that might help.
I get this error when the program tries to exit and all the Destructors are automatically called(ie. my program doesnt call this Destructor, because its not a pointer)
Then the Debugger says, Access Violation. It points to the first delete in the Destructor(I only have deletes in the Destructor).
Then, in the debugger window on the bottom, I click on *this. Every variable says:
"Error: expression cannot be evaluated"
And on the pointers it says:
"Error: symbol "" not found"

I am assuming that means that a destructor is being called on something that doesnt exist(ie, all ready delete''d?).

Though I dont understand because the class is held like this:
    class CMap {public:	//Member Variables	COctree			Octree;//RIGHT HERE	CVertex			*Vertex;	CFace			*Face;	unsigned int	numVertex;	unsigned int	numFace;	float			*tu;	float			*tv;	bool			isOK;	//Member Functions	void			Init(){isOK=true;}	void			End(){isOK=false;}	bool			IsOK(){return isOK;}	void			DrawOctree(COctree *node);	int				LoadASE(char *filename);	int				DrawMap();		//Constructor/Destructor	CMap()	{		Vertex=0;		Face=0;		tu=0;		tv=0;	}	~CMap() 	{		if(Vertex)delete [] Vertex;		if(Face)delete [] Face;		if(tu)delete [] tu;		if(tv)delete [] tv;		Vertex=0;		Face=0;		tu=0;		tv=0;	}};    


As you can see, I cannot call delete on that because it is not a pointer. The program automatically delete''s it on termenation. So how am I having a problem. All my code does is call the build() function in the code in my last post. What other code do you need?
Here''s a BRUTE FORCE method I had to use once. I had this same problem. Import your code to a console application. In every constructor add This

cout << "Constructing COctree" << endl; //or whatever type it is
getch();

and in every destructor add this:

cout << "Destructing COctree" << endl;
getch();

You will find your error this way by single stepping through the program. By the way, are you using any kind of copy constructor that you arent listing? SOMETIMES copy constructors can cause errors that are HARD AS HELL to find.

this should help,
sktizo_smurf
"Innocent is just a nice way to say ignorant, and stupidity is ignorance with its clothes off."words of,skitzo_smurf

This topic is closed to new replies.

Advertisement