Print Page | Close Window

Crash in CXTPPaintManager::DrawControl()

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=15036
Printed Date: 21 June 2025 at 6:43pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Crash in CXTPPaintManager::DrawControl()
Posted By: jasonaross
Subject: Crash in CXTPPaintManager::DrawControl()
Date Posted: 24 August 2009 at 2:45pm

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



Replies:
Posted By: Oleg
Date Posted: 25 August 2009 at 5:39am

Hi

I guess problem somewhere else in your code. Maybe you store some pointer to some control and call it after you removed it and it not valid anymore.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS



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