In CFrameWnd, the program crashes as stated below:
if (pDocument != NULL && pDocument->m_bAutoDelete)
{
BOOL bOtherFrame = FALSE;
POSITION pos = pDocument->GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = pDocument->GetNextView(pos); //dies at this point
ENSURE_VALID(pView);
if (pView->GetParentFrame() != this)
{
bOtherFrame = TRUE;
break;
}
}
if (!bOtherFrame)
{
pDocument->OnCloseDocument();
return;
}
// allow the document to cleanup before the window is destroyed
pDocument->PreCloseFrame(this);
}
// then destroy the window
DestroyWindow();
So, I thought maybe try to set autodelete to false and then delete it
afterwards. Unfortunately, now it dies at DestroyWindow. Anyone have
any idea why it's crashing like this?
Thanks,
Josh McFarlane
How, what are you doing?
>In CFrameWnd, the program crashes as stated below:
Is this MFC code or your code?
Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
I've overwritten the CMainFrame::OnClose to throw a final shutdown to
my alternate threads, then post another WM_CLOSE message. On the 2nd
pass through it calls the parent function CFrameWnd::OnClose(), which
crashes as specified above.
> Is this MFC code or your code?
The above posted code is MFC code.
I've tried numerous things, such as setting autodelete on the document
to false, and then deleting it after CFrameWnd::OnClose, which causes a
crash on the DestroyWindow instead of MFC. I've also tried deleting the
document before hand, which cause OnClose to complete successfully, but
then returns to the message pump rather than killing the App.
How should I close the application from CMainFrame::OnClose?
Doing this is most likely the root cause of the problem.
Presumably you want to synchronise the close down of worker threads in
your application at this point - if so, why don't you just have your
OnClose handler wait until they've finished rather than create another
WM_CLOSE message?
The worker threads while shutting down post messages to the parent
thread with data that needs to be dealt with. After they shutdown
successfully, I post the WM_CLOSE to ensure that any prior thread
messages are handled before the actual shutdown. I'll post the code
this afternoon.
Josh
I just tried the basic troubleshooting step I forgot to do: Using
default WM_CLOSE handler. Same error message, same problem. I think
this may have something to do with the fact that I never really use the
Doc, only the View. I leave the default document open and just draw
images from the inputs on the screen.
Is there a special function I'm suppose to call on the Document or View
before calling WM_CLOSE?
If you just do nothing with the document, the default operation should
work. However, if you mean that you do something to subvert the
default behaviour - that may be another kettle of fish.
The best suggestion I can make at this stage is to re-check your ideas
in a clean project to eliminate anything you've done in your real
project.
See, that's the weird thing. The only real doc / view action I ever do
is overriding the OnDraw for the View, which draws the image data that
is coming in via the other threads. In theory this should do nothing,
as there is no new / open / close doc menu items.
Try prototyping a simple version of your closedown operations in a
clean project and let us know how to reproduce the behaviour you're
getting.