Print Page | Close Window

10.4.2 print preview assert/crash

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Calendar
Forum Description: Topics Related to Codejock Calendar
URL: http://forum.codejock.com/forum_posts.asp?TID=6364
Printed Date: 04 May 2024 at 8:39am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: 10.4.2 print preview assert/crash
Posted By: Algae
Subject: 10.4.2 print preview assert/crash
Date 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.





Replies:
Posted By: sserge
Date 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


Posted By: Algae
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net