Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Calendar
  New Posts New Posts RSS Feed - 10.4.2 print preview assert/crash
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

10.4.2 print preview assert/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: 10.4.2 print preview assert/crash
    Posted: 09 February 2007 at 3:18pm

Hello,

I noticed the following bug while running a version of my app using 10.4.2.

When you close the application with a calendar view print preview active it will assert (crash in release) in the destructor at the noted line:

CXTPCalendarControlView::~CXTPCalendarControlView()
{
    if (m_bReleaseCalendarWhenDestroy)
    {
        CMDTARGET_RELEASE(m_pCalendar);
    }

    ASSERT(m_pUpdateContect == NULL); // <<<< will assert here
    SAFE_DELETE(m_pUpdateContect);

    CMDTARGET_RELEASE(m_pPrintOptions);
}

Apparently the contect (context?) isn't freed up ahead of time. This bug is also present in the calendardemo sample.


Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post Posted: 09 February 2007 at 5:12pm
Normally m_pUpdateContect (yes, should be context) is destroyed in CXTPCalendarControlView::OnEndPrinting.
 
This ASSERT means that PrintPreview was not correclty finished.
 
And how can you exit app without closing PrintPreview first?

What is your VC version 6.0, 7.0, 7.1,  8.0 ?
 
I tried on Calendar Demo sample - both Alt+F4 and "x" button close PrintPreview on first click, on the second one app is closed.

--
WBR,
Serge
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: 10 February 2007 at 7:42pm
Solved. It had nothing to do with the Codejock code.

Sserge's hint regarding "And how can you exit app without closing PrintPreview first?" tipped me off to trace there. I was assuming PrintPreview would close itself! This is not always the case.

I was running both the sample and my app through an MDI framework. In the MDI framework the order of dispose is ordered from 1st to last view on the same doc. The Calendar view was being disposed before the Preview view and the Preview view close could never be reached.

In order to solve, set a BOOL flag in the doc that the Preview view is associated with. In the "OnCloseDocument()" in the doc file, catch the flag and send a close preview message to all the views associated with the doc.

void CCalendarDoc::OnCloseDocument()
{
 if ( m_bIsPreview )
 {
    m_bIsPreview = FALSE;
    POSITION pos = GetFirstViewPosition();
    while (pos != NULL)
    {
        CView* pView = GetNextView(pos);
        pView->SendMessage( WM_COMMAND, AFX_ID_PREVIEW_CLOSE, 0);
    }
    return;
 }
    // rest of close document stuff here
}

In the view where you have the print preview, OnFilePrintPreview(),  set the BOOL flag so the document knows the status if it goes to close:

void CCalendarView::OnFilePrintPreview()
{
    CCalendarDoc* pDoc = (CCalendarDoc*)GetDocument() ;
    pDoc->m_bIsPreview = TRUE ;

    // rest of the printpreview stuff goes here
}

Now you should be able to close the document by any normal means and it will pick up and send the signal to close printpreview.

Thanks for the hint Sserge
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.141 seconds.