My application crashes when dereferencing a null pointer within DrawControl. Any ideas on whether this is a codejock issue or something i can prevent? My application has framework that can load different dlls/components dependent on the user action. As different components are loaded, we remove controls in the CXTPMenu bar and add some back.
CXTPPaintManager::DrawControl(CDC* pDC, CXTPControl* pButton, BOOL bDraw)
…
return (pButton->GetParent()->GetType() == xtpBarTypePopup)? //crashes when getting the type for the parent of the button
DrawControlPopupParent(pDC, pButton, bDraw): DrawControlToolBarParent(pDC, pButton, bDraw);
Rewritten..
CXTPCommandBar* pjCXTPCommandBar = pButton->GetParent();
XTPBarType aXTPBarType = pjCXTPCommandBar->GetType(); //crashes here as pjCXTPCommandBar is NULL
return (aXTPBarType == xtpBarTypePopup)?
DrawControlPopupParent(pDC, pButton, bDraw): DrawControlToolBarParent(pDC, pButton, bDraw);
CXTPControl::Draw(
CXTPCommandBar::DrawCommandBar(
CXTPCommandBar::OnPaint()
CXTPCommandBar::OnWndMsg(
CXTPCommandBar::DrawCommandBar(
CXTPCommandBar::OnPaint()
CXTPCommandBar::OnWndMsg(
CWnd::UpdateWindow()
CXTPPopupBar::SetTrackingMode(int 0, int 1, int 0)
CXTPCommandBar::OnDestroy()
CXTPCommandBar::OnWndMsg(
CXTPHookManager::HookWndProc(
CXTPCommandBar::OnFinalRelease()
CXTPControlPopup::~CXTPControlPopup()
CXTPControlPopup::`vector deleting destructor'(
CXTPControls::RemoveAll()
CEnhancedMenuController::AddComponentMenu //from my app
It seems the CXTPControl objects' parent is set to null within CXTPControls::RemoveAll().
void CXTPControls::RemoveAll(void)
{
for (int nIndex = 0; nIndex < GetCount(); nIndex++)
{
CXTPControl* pControl = m_arrControls.GetAt(nIndex);
pControl->m_pControls = NULL;
//pControl->m_pParent = NULL; commenting out this line prevents the crash
pControl->InternalRelease();
}
m_arrControls.RemoveAll();
}
------------------
void CEnhancedMenuController::AddComponentMenu(long hMenu) { componentCommandIds.RemoveAll(); CString menuString; try { CPVFrame* ownerFrame = dynamic_cast<CPVFrame*> (m_ownerWnd); if (ownerFrame == NULL) { MsgWriteF (MSG_DEFAULT, eMsgLog_Commit, _T("PVAPP"), eMsgLvl_Info, _T("CEnhancedMenuController::AddComponentMenu cast of m_ownerWnd to PVFrame* returned NULL")); return; } CXTPCommandBars *pCommandBars = ownerFrame->GetCommandBars();
//The codejock menu bar CXTPMenuBar* pMenuBar = static_cast<CXTPMenuBar*> (pCommandBars->GetMenuBar()); //CMenu we build first CMenu* pMenu = NULL; if (m_hFrameworkMenu == NULL) { pMenu = new CMenu(); pMenu->CreateMenu(); m_hFrameworkMenu = pMenu->m_hMenu; } else { pMenu = CMenu::FromHandle(m_hFrameworkMenu); for (int i = pMenu->GetMenuItemCount() - 1; i >= 0; i--) { pMenu->RemoveMenu(i, MF_BYPOSITION); } }
//remove anything currently in the array CleanUpMenuArray();
CXTPControls* curControls = pMenuBar->GetControls(); curControls->RemoveAll(); //sets off the crash
-----------
Thanks in advance!
------------- Product: Xtreme Toolkit Pro v9.70
Platform: Windows XP (32bit) - SP 2
Language: Visual C++ 6.0
|