Archived

This topic is now archived and is closed to further replies.

LogSoulz

deconstructing exceptions woes...

Recommended Posts

Hello, I''m having trouble with deconstructing my SceneGraph class. Exception would be thrown, why I don''t know... Help me out here ya''ll. my class hierarchy: I have 3 classes KSceneGraph, KTransformNode, and KGeoNode derived from KObject class. KSceneGraph contains a list of KTransformNodes and KtransformNodes contain a leaf node which is a KGeoNode object. Here is a simple console program to illustrate my problem:
KSceneGraph root;

int main()
{
	

	char text_1[50];
	char text_2[50];
	char text_3[50];

	KTransformNode* node;
	
	node = new KTransformNode();
	node->init();

	root.attachTransformNode(node);

	
	delete node; //throws exception here...



	return 0;

}

 
And the part that is the problem...this is where the debugers get stuck at...
KTransformNode::~KTransformNode()
{

	
	while(head->next !=NULL)
	{
		current = head->next;
		head->next = current->next;
		delete current;
	}
	
	delete GeoNode;
	
	delete head;


}
 
All help appreciated.

Share this post


Link to post
Share on other sites
What are ''head'' and ''current'' in your KTransformNode destructor?

Are the aLso KTransformNodes?

When you construct whatever it is, are you setting the ->next value to NULL initially? If you do not set it to NULL in the beginning, when you do if (head->next != NULL) it will most likely still pass even if it was never assigned a node. So you will be trying to destruct something that is not really there.

Otherwise I would use Run To Cursor in Debug to the first line of the destructor and step through, checking the values of each pointer before it is destructed.

Seeya
Krippy

Share this post


Link to post
Share on other sites
Thanks!

I fixed it. Seems like it was caused by the ordering or the deconstruction(whatever that means), so I implemented a free_node method which does the desconstruction, and it works! Yay, it feels so good after a long session of bug slaying, and heck no I don't like bugs. I sound like they're my friends or something, anyway to the coffee machine!


node->free_nodes();
delete node;



Edited by - LogSoulz on June 29, 2001 9:09:07 PM

Share this post


Link to post
Share on other sites