|
-
Jan 6th, 2003, 11:20 AM
#1
Thread Starter
Addicted Member
Debug assertion error when deleting class
I have a dll that contains a global variable. This global variable is a class:
In an exported function I call:
Code:
mcClass = new MyClass(...);
which obviously constructs the class. However, I then wanted to add the ability to call that function, but if the var mcClass has already been initialised, I wanted it to delete it first. So, in DllMain I placed:
On the call to my function it would therefore do:
Code:
if(mcClass != NULL)
delete mcClass;
mcClass = new MyClass;
However, when this executes in Debug mode, it causes an Assertion Error:
Code:
Expression: _CrtIsValidHeapPointer(pUserData)
Why is this the case? Surely if the class is global, it can be deleted wherever?
Thanks
HD
-
Jan 6th, 2003, 01:32 PM
#2
Are you sure it's this very deletion instruction that causes the exception? Couldn't it also be some other code?
Could it be that you overwrite the pointer somewhere? Maybe the class destructor does something bad.
Have you tried a debugging run to execute the suspicious code line by line?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|