Hi all,
I'm trying to figure out why TH I get these error
unhandled exception at <address No.> in <my project neme>.exe:
<address No.>: Privileged instruction
and another :
unhandled exception at <address No.> in <my project neme>.exe:
<address No.> : Access violation writing location <address No.>

when I try to debbug it by choosing break , the curser stands on the delete row:

if(!this->m_PostersPost.empty()){
	list<Text*> ::iterator itp;
	for(itp = this->m_PostersPost.begin(); itp != this->m_PostersPost.end(); itp++){
		delete(*itp);
	}

I tried to add an if(itp!=NULL) statement in all forms (&& ( *itp!=NULL), and only one of them alone) but it got even worse. What do I do wrong?
thanks in advance,
Yael

It seems the cause of your problem is bad pointers (for example, these Texts objects are deleted before). In any case we need more wide context to help you.
Apropos, delete null pointer is a valid operation (do nothing).

Well, these objects are on the heap and this is the first place I'm trying to delete them. I added a check up in the destructor of this class, that holds the list, for a memory leak prevention, but that's it. I can't really understand the problem. More, it doesn't always happen, and when it does, I get one of the errors above. Is there a connection between them?

Three possibilities I can think of offhand.

1) The way you have created the individual objects (which you haven't shown) is inconsistent with the way you're destroying them.

2) Some operation of the Text type is invalid (eg it mangles a pointer to data internally).

3) Some other code is doing an invalid pointer operation, and that is not being detected until you reach the code you've given.

When a crash occurs, any previously executed code is a potential culprit. In practice, you actually have to be very lucky to have a crash occur at the offending line.

Ok, entering a white night of debugging. In the mean time... thanks for now.

Actually, the biggest problem was the deleting an array (char*) without using the [] as:

delete [] array_name;

so I had a memory leak and all (but that wasn't the only problem. I had some... yet, this one was the greatest problem in my code...)- just wanted others who'll reach this page to know...
good luck you all.
and thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.