Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Calendar
  New Posts New Posts RSS Feed - Calender event Smart Pointer crash.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Calender event Smart Pointer crash.

 Post Reply Post Reply
Author
Message
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Topic: Calender event Smart Pointer crash.
    Posted: 06 November 2010 at 2:12pm
This has been bothering me for a long time. Maybe I'm missing something really obvious.

My program can close while the event properties dialog is still open. The program will crash when exiting because of the event smart pointer in the dialog. See m_ptrEditingEvent in the Calendar sample.

I can't seem to get rid of this pointer cleanly. I have tried every method of release and destruct and detach I can think of and nothing seems to work.

I don't, and cannot, create a reference to the event dialog to refer back to it and close it. Based on the program design of being able to open multiple event dialogs concurrently that isn't an option.

Is there a way I can get rid of this pointer before the view/controller etc. goes away?

Thanks if you can help!


Back to Top
Marco1 View Drop Down
Senior Member
Senior Member


Joined: 16 January 2004
Location: Germany
Status: Offline
Points: 251
Post Options Post Options   Thanks (0) Thanks(0)   Quote Marco1 Quote  Post ReplyReply Direct Link To This Post Posted: 08 November 2010 at 8:48am
Sorry to say, but it sounds like a bad design for me.
If the program (with its calendar event database) closes, the pointers of the dialog get invalid and point to nowhere.
The correct closing order should be to close all open (nonmodal) prop dialogs first and then the main program.

1. I guess you have a handler somewhere which creates the nonmodal dialog. You should store the pointer to the new dialog in a vector somewhere in the mainfraime/app and iterate through this list in OnClose (or whatever) and destruct all open dialogs properly.
2. Or you derive your own prop dlg class which registers itself in the vector (e.g. in ctor / OnCreate). Getting a pointer to the main wnd is always possible.

Closing the prop dlg removes the pointer out of the vector.

I'm aware you said you don't have and cannot create a ref to the dialog - but you should...
Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 07 December 2010 at 5:21pm
Thanks Marco,

I expected the answer you gave as that's what I would have suggested too Smile

That means I'll likely have to create a list of dialog references and push/pop them just for the calendar module. Ugly bunch of overhead for the one time shutdown process in case all the event dialogs aren't closed. I don't know exactly why the calendar behaves differently as I use the same nonmodal construct everywhere without ill effect.



Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 14 December 2010 at 4:52pm
After implementing a list of dialog pointers and closing on exit, I can say..

that's not it!

My dialogs cleaned up fine without all that. There's some kind of pointer or sink or something that calendar wants to hang onto. Back to the drawing board.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.