Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Apply exception Collapse All
Subject Author Date
Constantine Zzz Jul 17, 2007 - 3:34 AM

I’ve got a CTreeCtrl and CExtPropertGridCtrl.

In Tree shows strucuture of objects. Propertys of selected in tree object shows in PropertyGrid.

When I change some properties in Apply I use my function CTreeCtrl->Invalidate(). Which updates tree by objects properties. On tree root it runs good (i change tree root’s property,in Apply() of property I use tree->ivalidate(), works fine).

But when I change property of anoter object (properties are different for root and this object). tree->invalidate() crashes with exception.

CTreeCtrl I getting same way in both cases.

code for tree root.

void CTreeRoot_Dir::Apply( CExtGridCell * pValue )
{
ASSERT_VALID( this );

#ifdef _DEBUG
if( pValue != NULL )
{
ASSERT_VALID( pValue );
ASSERT_KINDOF( CExtGridCellFolder, pValue );
}
#endif // _DEBUG
CTreeRoot_PropertyValueBase::Apply( pValue );

if( m_pTR == NULL )
return;
    
        CExtGridCellFolder * pV = STATIC_DOWNCAST( CExtGridCellFolder, ( ( pValue == NULL ) ? ValueActiveGet() : pValue ) );
     CExtSafeString t;
        pV->TextGet(t);
        if (t != m_pTR->GetDir ())
        {
            //
            CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
            CfceditDoc* pDoc = CfceditDoc::GetDoc();
            ASSERT(pFrame);
            ASSERT(pDoc);

            m_pTR->SetDir( t );
            if(!pDoc->UpdateResourceGroups())
            {
                AfxMessageBox(_T("Error!"), MB_OK|MB_ICONEXCLAMATION);
                return;
            }
            m_pTR->ResetFullfilled();
            m_pTR->UpdateFull();
            pFrame->GetTree()->SetStyle(TVS_HASBUTTONS, true);
            pFrame->GetTree()->Invalidate();
        }
}

code for simple object.

void CTreeItem_ID::Apply( CExtGridCell * pValue )
{
    ASSERT_VALID( this );

#ifdef _DEBUG
    if( pValue != NULL )
    {
        ASSERT_VALID( pValue );
        ASSERT_KINDOF( CExtGridCellString, pValue );
    }
#endif // _DEBUG
    CTreeItem_PropertyValueBase::Apply( pValue );

    if( m_pTI == NULL )
        return;

    CExtGridCellString * pV = STATIC_DOWNCAST( CExtGridCellString, ( ( pValue == NULL ) ? ValueActiveGet() : pValue ) );

    CString t;
    pV->TextGet(t);

    if ( t != "")
    {
        CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
        ASSERT(pFrame);

        t.MakeUpper();
        pV->TextSet(t);
        m_pTI->SetID( t );
//works
        pFrame->GetTree()->SetStyle(TVS_HASBUTTONS, false);
        
//exception
pFrame->GetTree()->Invalidate();
    }
}

GetTree() simple return pointer to CTreeCtrl

Invalidate code.
void CGameTree::Invalidate(HTREEITEM _hti)
{
    CTreeItem *ti = NULL;
    HTREEITEM hti;

    if ( _hti == NULL )
    {
        VERIFY(
            DeleteAllItems()
            );
        hti = Init();
    }
    else
    {
        hti = _hti;
        ti = (CTreeItem*)GetItemData(hti);
    }


    //updates internal structure of tree
UpdateTree(ti);
    
//updates CTreeCtrl structure (by CTreeCtrl->Insert method)
    Update(ti);

    Expand(hti, TVE_EXPAND);
}
It may crash on DeleteAllItems(), or can goes further and crash on CTreeCtrl->Insert (...).

What I did wrong?

Constantine Zzz Jul 18, 2007 - 9:43 PM

Yes, you’re right. Thank you. :)

Technical Support Jul 18, 2007 - 10:58 AM

We believe the problem is specific to your project only and your code should handle selection changing in the tree control for changing the property grid’s content. Your code deletes and inserts tree items and some conflict may occur due to this. If it is not possible to avoid insertion/deletion, then you need to protect the property grid updating with some flag variable until the tree updating is completed. If you have a subscription, you can send us your project so we can clarify what is wrong.

Constantine Zzz Jul 18, 2007 - 3:59 AM

Anyway, thanx.

Constantine Zzz Jul 18, 2007 - 3:58 AM

I think, I’ve found mistake.

while Apply not ended, by Invalidate I changing PropertyStore to PropertyGridCtrl (invalidate selects root of tree with it’s property store)

Constantine Zzz Jul 18, 2007 - 2:08 AM

Call Stack shows that exception was in
CExtGridInplaceEdit::WindowProc(unsigned int message=865, unsigned int wParam=0, long lParam=1233564)

Constantine Zzz Jul 17, 2007 - 7:26 PM

in Release cfg this code works, in Debug crashes