Urgent problem with CXTPPropertyGridItemFont |
Post Reply |
Author | |
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
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!
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
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.
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
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?
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
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!
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
znakeeye
Senior Member Joined: 26 July 2006 Status: Offline Points: 1672 |
Post Options
Thanks(0)
|
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? |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |