Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
HP Jiang
|
Sep 23, 2009 - 2:16 AM
|
CTimeControlLabel class inherits from CExtBarLabelButton. CTimeControlLabel shows the time on the toolbar every second. but, this instance of CTimeControlLabel causes crashes very about 3 mins, the call stack shows below, who know the reason of crash?
ntdll.dll!7c90120e() [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] > msvcr80d.dll!_CrtDbgBreak() Line 89 C msvcr80d.dll!_VCrtDbgReportA(int nRptType=2, const char * szFile=0x781df018, int nLine=716, const char * szModule=0x00000000, const char * szFormat=0x00000000, char * arglist=0x00124e04) Line 290 C msvcr80d.dll!_CrtDbgReportV(int nRptType=2, const char * szFile=0x781df018, int nLine=716, const char * szModule=0x00000000, const char * szFormat=0x00000000, char * arglist=0x00124e04) Line 300 + 0x1d bytes C msvcr80d.dll!_CrtDbgReport(int nRptType=2, const char * szFile=0x781df018, int nLine=716, const char * szModule=0x00000000, const char * szFormat=0x00000000, ...) Line 317 + 0x1d bytes C mfc80d.dll!AfxAssertFailedLine(const char * lpszFileName=0x781df018, int nLine=716) Line 25 + 0x14 bytes C++ mfc80d.dll!CDC::SetLayout(unsigned long dwSetLayout=0) Line 716 + 0x18 bytes C++ ProfUIS284md.dll!01a6db9c() ProfUIS284md.dll!01a6e1ac() ProfUIS284md.dll!01e10e77() ProfUIS284md.dll!01e147ca()
source code is here,
class CTimeControlLabel : public CExtBarLabelButton { public: CTimeControlLabel( CExtToolControlBar * pBar = NULL, UINT nCmdID = ID_SEPARATOR, UINT nStyle = 0 ); void setCaption(const std::string & strCaption) { m_strCaption = strCaption; //RedrawButton(); } virtual ~CTimeControlLabel(); virtual void Paint( CDC & dc);
virtual CSize CalculateLayout( CDC & dc, CSize sizePreCalc, BOOL bHorz );
private: static std::string m_Title; std::string m_strCaption;
CSize m_sizeFunnyTextCalc, m_sizeFunnyTextWell; };
cppfile
std::string CTimeControlLabel::m_Title = "Training Time"; CTimeControlLabel::CTimeControlLabel(CExtToolControlBar * pBar, UINT nCmdID , UINT nStyle ): CExtBarLabelButton(pBar, nCmdID, nStyle) { }
CTimeControlLabel::~CTimeControlLabel() {
} //*ccccccccccccccccccc void CTimeControlLabel::Paint( CDC & dc) { CFont tile_font; tile_font.CreateFont( 16, // nHeight 0, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily "Arial"); // lpszFacename CFont* pFont = dc.SelectObject(&tile_font); CRect rect(m_ActiveRect); dc.DrawText(m_Title.c_str(), &rect, DT_CENTER); dc.SelectObject(pFont); tile_font.DeleteObject();
CFont font; font.CreateFont( 48, // nHeight 16, // nWidth 0, // nEscapement 0, // nOrientation FW_SEMIBOLD, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily "Arial"); // lpszFacename
CFont* def_font = dc.SelectObject(&font); rect.DeflateRect(0, 10, 0, 0); dc.DrawText(m_strCaption.c_str(), &rect, DT_CENTER|DT_VCENTER); dc.SelectObject(def_font); // Done with the font. Delete the font object. font.DeleteObject();
}//*/
CSize CTimeControlLabel::CalculateLayout( CDC & dc, CSize sizePreCalc, BOOL bHorz ) { ASSERT_VALID( this ); CSize _size = CExtBarButton::CalculateLayout( dc, sizePreCalc, bHorz ); ASSERT( !IsSeparator() ); if( ! m_strCaption.empty() ) { CFont * pOldFont = dc.SelectObject( &g_PaintManager->m_FontNormal ); CRect rcMeasured( 0, 0, 0, 0 ); dc.DrawText( m_strCaption.c_str(), &rcMeasured, DT_LEFT|DT_CALCRECT ); m_sizeFunnyTextWell = rcMeasured.Size(); m_sizeFunnyTextWell.cx += __EXT_TB_BUTTON_TEXT_MARGIN*2; static CString strMeasureTemplate( _T("AapqWZz\nAapqWZz") ); dc.DrawText( strMeasureTemplate, &rcMeasured, DT_LEFT|DT_CALCRECT ); dc.SelectObject( pOldFont ); m_sizeFunnyTextCalc = rcMeasured.Size(); m_sizeFunnyTextCalc.cx += __EXT_TB_BUTTON_TEXT_MARGIN*2; m_sizeFunnyTextCalc.cx = max( m_sizeFunnyTextWell.cx, m_sizeFunnyTextCalc.cy ); m_sizeFunnyTextCalc.cy = max( m_sizeFunnyTextWell.cy, m_sizeFunnyTextCalc.cy ); m_sizeFunnyTextCalc.cx += __EXT_TB_BUTTON_INNER_MARGIN*2; _size.cx = max( m_sizeFunnyTextCalc.cx, _size.cx ); _size.cy += m_sizeFunnyTextCalc.cy + 4; } // if( ! m_strFunnyText.IsEmpty() ) m_ActiveSize = _size; m_ActiveSize.cx = m_ActiveSize.cx + 150; return m_ActiveSize; }
|
|
Technical Support
|
Sep 25, 2009 - 6:42 AM
|
If you have 5000 GDI handles, then everything runs notably slower. If you have 1000 GDI handles, then any text is painted with the "System" font, bitmaps and icons are not painted at all. This is the limit of GDI. Normal application does not require such large counts of GDI handles. This is definitively the leak of GDI handles and you should find and fix it.
|
|
Technical Support
|
Sep 24, 2009 - 4:19 AM
|
Your source code is OK. Could you insert it into some sample project provided with Prof-UIS (SDI, SDIDOCVIEW), reproduce the crash problem and then send the modified project to us? We guess the problem is really hidden in somewhere else like GDI handle leaks.
|
|
HP Jiang
|
Sep 23, 2009 - 11:43 PM
|
From the task manager, I saw the GDI Objects number is about 9998, then the application crashed at above point.
so bad.
wuwh
|
|