Skip to main content
gamedev.net
🔒 Locked

Inconsistent destructors...

Started by evanofsky May 21, 2006 at 8:05 PM 2 replies 750+ views
Original Post
evanofsky
evanofsky
So let's say I have a program like this:

class Object {
public:
   Object();
   ~Object();
   void foo();
};

Object::Object() {/** ... */}

Object::~Object() {
   PrintOutMessageToCommandPrompt();
}

int main() {
   Object object;
   object.foo();
}


This is basically what's happening in my current project. However, PrintOutMessageToCommandPrompt() is never called. If instead I do this:

int main() {
   Object* object = new Object();
   object->foo();
   delete object;
}


It calls PrintOutMessageToCommandPrompt(). I'm using VC++.net 2003. I'm pretty sure it has nothing to do with any of the code implementation details; I'm just calling ::MessageBox() in the actual code. Thanks alot! [smile]
Fruny
Fruny
Quote:
Original post by evanofsky
I'm pretty sure it has nothing to do with any of the code implementation details; I'm just calling ::MessageBox() in the actual code.


Try printing something on the standard error stream (std::cerr) instead.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
iMalc
iMalc
Quote:
Original post by Fruny
Quote:
Original post by evanofsky
I'm pretty sure it has nothing to do with any of the code implementation details; I'm just calling ::MessageBox() in the actual code.


Try printing something on the standard error stream (std::cerr) instead.
In other words, the object is destructed at a point at which it is no longer valid to display a messagebox since your app is mostly destroyed.

A breakpoint in the destructor should confirm that the code is still being reached.
evanofsky
evanofsky
Okay, that makes sense. It reaches the breakpoint now. The reason I asked this question is because PIX told me that none of my textures had been deleted. Of course, I never explicitly delete them, because I'm using an ID3DXEf- nevermind, this is a question for the DirectX forum. [wink]

Thanks alot for the help!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.