Sign in to follow this  

destructor?

This topic is 3631 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how do destructors work as i create a local object instead of a global object and my destructor gives me errors. to fix this i create another function which i call to clean up code and now it works . i create the object camera cam; camera::~camera(){ //if(g_font2){ // g_font2->Release();//error access violation // g_font2=NULL; // } } void camera::shutdown() //newly created and now it all works { if(g_font2) { g_font2->Release(); g_font2=NULL; } }

Share this post


Link to post
Share on other sites
what code to you need as i gave all relevant parts. i didnt give fuction declarations but they are too simple to give

eg in .h ~camera();
void shutdown(void);

or call cam.shutdown();

Share this post


Link to post
Share on other sites
Quote:
Original post by jagguy2
what code to you need as i gave all relevant parts. i didnt give fuction declarations but they are too simple to give

eg in .h ~camera();
void shutdown(void);

or call cam.shutdown();



Nope. We have no idea where the camera is initialised, what or where g_font is etc. This is the information we need.

Share this post


Link to post
Share on other sites
all in the same winMain function


int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
WNDCLASSEX winClass;
MSG uMsg;
HRESULT hr;
camera cam;
....
....
if (FAILED (hr=D3DXCreateFont(g_pd3dDevice, 20,0,FW_NORMAL, 1,
false,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,
L"Arial",&g_font)) )
MessageBox(NULL,L"User Abort",L"font error",MB_OK);
...
...
render(cam);

}


shutDown();
cam.shutdown();

Share this post


Link to post
Share on other sites

PS the code does work if i dynamically allocate space for 'cam' as

in winMain

camera *cam= new camera;
//camera cam;

i then use delete and my destructor works correctly.

Share this post


Link to post
Share on other sites
Your code still isn't clear to me. Can you fix the formatting so that it's immediately clear how things are lined up and what code is part of what code block? Also, where is g_font declared? And what is g_font2?

Share this post


Link to post
Share on other sites
When you have a problem like this, one thing you can try is putting together a minimal, but complete, source dump of the issue. That is, try to create a program that misbehaves in exactly the same way. One way to do that is to create a new project and add to it until you get the problem. Another way is to create a copy of your existing project and start deleting code until you can't delete anymore and still have the same problem. Doing so may give you a better understanding of the issue. At the very least, it gives you something useful to post.

Share this post


Link to post
Share on other sites

This topic is 3631 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this