Print Page | Close Window

Urgent problem with CXTPPropertyGridItemFont

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Property Grid
Forum Description: Topics Related to Codejock Property Grid
URL: http://forum.codejock.com/forum_posts.asp?TID=7179
Printed Date: 14 May 2024 at 11:12am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Urgent problem with CXTPPropertyGridItemFont
Posted By: znakeeye
Subject: Urgent problem with CXTPPropertyGridItemFont
Date Posted: 18 May 2007 at 7:27pm
Open the DrawClient sample, open MainFrm.cpp and go to line 264.
Then add this:
 
LOGFONT lf = { 0 };
pCategorySelected->AddChildItem(new CXTPPropertyGridItemFont(_T("font test"), lf));
 
Debug the application and then click on button of the newly added font property. The font dialog appears. Now Alt+Tab to another application. Switch back to the font dialog and press ok. BOOM! We get a heap error at line 164 in xtppropertygriditemfont.cpp:
CString strValue = FontToString(lf);
 
In some cases you break deep inside the C heap library. What's going on here?
 
Please help!



Replies:
Posted By: Oleg
Date Posted: 19 May 2007 at 2:03am

Hello,

Yes, thanks, this is problem of sample - not code.
 
in CDrawView::OnActivateView replace
 
 if (!bActivate)
  ((CMainFrame*)AfxGetMainWnd())->UpdatePropertyGridContent(0);
to
 if (!bActivate && AfxGetMainWnd()->IsWindowEnabled())
  ((CMainFrame*)AfxGetMainWnd())->UpdatePropertyGridContent(0);


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


Posted By: znakeeye
Date Posted: 19 May 2007 at 7:15am
You're on the right track, but that fix doesn't work.
 
As soon as UpdatePropertyGridContent is called (not just from that line), the destructor of the font item is called - causing the heap error. I tried adding this in CMainFrame::UpdatePropertyGridContent():
if (!IsWindowEnabled()) return;
 
... but it didn't help either.


Posted By: Oleg
Date Posted: 21 May 2007 at 1:14am
Strange. it works for me.
 
If you set breakpoint after if (!IsWindowEnabled()) return; in the UpdatePropertyGridContent, show font dialog box  and switch application does it fired?


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


Posted By: znakeeye
Date Posted: 21 May 2007 at 3:00am
No, it doesn't - until I press OK/Cancel. When I close the font dialog, UpdatePropertyGridContent is actually called before DoModal() is finished. I think this is a race condition. It might work in some cases.
 
Any further ideas?


Posted By: Oleg
Date Posted: 21 May 2007 at 4:59am
You right. Please  try this changed method:
 
void CDrawView::OnActivateView(BOOL bActivate, CView* pActiveView,
 CView* pDeactiveView)
{
 CView::OnActivateView(bActivate, pActiveView, pDeactiveView);
 CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd(); 
 if (!bActivate && !pMainFrame->IsWindowEnabled())
  return;
 // invalidate selections when active status changes
 if (m_bActive != bActivate)
 {
  if (bActivate)  // if becoming active update as if active
   m_bActive = bActivate;
  if (!m_selection.IsEmpty())
   OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  m_bActive = bActivate;
 }
 if (!bActivate && pMainFrame->MDIGetActive() != GetParentFrame())
 {
  pMainFrame->UpdatePropertyGridContent(0);
 }
}
 
For next maintaince release we will update our code to not crush even if item was removed while dialog is visible.
 
Thanks, let me know it it will work for you.


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


Posted By: znakeeye
Date Posted: 21 May 2007 at 7:14am

Yes, it works =)

What kind of method will you use for the mutual exclusion? Please implement a general solution that would work for a custom-made propertygrid item where a dialog is shown. Recall your Grid sample where this can be found:

virtual void OnValueChanged(CString strValue)
{
    if (strValue == _T("<Edit...>"))
    {
          CSomeDialog dlg(m_pGrid);
          
dlg.DoModal();
    }
    ...
}
 
Thanks!


Posted By: Oleg
Date Posted: 22 May 2007 at 1:19am
Hi,
 
We added InternalAddRef(); in begining of OnInplaceButtonDown and InternalRelease(); in the end, so even if item was removed from grid it will be deleted only in the end of OnInplaceButtonDown  method.


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


Posted By: znakeeye
Date Posted: 27 May 2007 at 4:20pm

Good. But what happens if the item is deleted and re-inserted into the grid while the dialog is visible? Then its value will not be updated when the user presses OK?



Posted By: Oleg
Date Posted: 28 May 2007 at 7:01am

Yes, will not be updated. So try not delete items while dialogs are visible. use code I wrote in 21 May.



-------------
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