Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Property Grid
  New Posts New Posts RSS Feed - Urgent problem with CXTPPropertyGridItemFont
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Urgent problem with CXTPPropertyGridItemFont

 Post Reply Post Reply
Author
Message
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Topic: Urgent problem with CXTPPropertyGridItemFont
    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!
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post 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!
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post 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?

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.