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 » Crash in ProfileBarStateLoad Collapse All
Subject Author Date
han chong tan Sep 29, 2009 - 2:16 AM

I’m having the same problem as in http://www.prof-uis.com/prof-uis/tech-support/support-forum/crash-in-profilebarstateload-57693.aspx.#@lt;/p>

try/catch block doesn’t prevent the crash:



    try

    {

        if( ! CExtControlBar::ProfileBarStateLoad(this,theApp.m_pszRegistryKey,theApp.m_pszProfileName,theApp.m_pszProfileName,&m_dataFrameWP, true, true, ((HKEY)(ULONG_PTR)((LONG)-2147483647)), true))

        {

            CRect rect;

            GetWindowRect(&rect);

            int nX = rect.Width();

            //int nY = rect.Height()/3;

            int nY = 400;

            m_wndMFSearchBar.SetInitDesiredSizeHorizontal( CSize(nX,nY) );

            m_wndMFSearchBar.DockControlBarInnerOuter(AFX_IDW_DOCKBAR_BOTTOM, true );

            m_wndMFSearchBar.AutoHideModeSet(false, true, true, false);

            RecalcLayout();

        }

    }



    catch (...)

    {

        CRect rect;

        GetWindowRect(&rect);

        int nX = rect.Width();

        //int nY = rect.Height()/3;

        int nY = 400;

        m_wndMFSearchBar.SetInitDesiredSizeHorizontal( CSize(nX,nY) );

        m_wndMFSearchBar.DockControlBarInnerOuter(AFX_IDW_DOCKBAR_BOTTOM, true );

        m_wndMFSearchBar.AutoHideModeSet(false, true, true, false);

        RecalcLayout();

    }



It crashed here (inside CExtControlBar::InternalFriendlyFrameWnd::SetOuterDockState()):



        if(        ( pExtBar->IsFixedMode() )

            ||    ( pExtBar->IsFixedDockStyle() )

            )

        {



pExtBar was null.



 



Any other way to prevent the crash?

Andre Vautour Apr 7, 2010 - 7:32 AM

I’ve also hit this problem.


The context is the following. A layout file was created. A later build of the application removed a toolbar that the user had as a floatting toolbar when the previous layout was created. Once the new build of the application loads the old layout, the following code crash throws a NULL pointer exception:


in CExtControlBar::InternalFriendlyFrameWnd::SetOuterDockState:

 


 

// the third pass will move independent floating bars

 

// into valid positions

 

{

OuterItemData_t _oid = arrOuterProps[i];

CExtControlBar * pExtBar =

STATIC_DOWNCAST(

CExtControlBar,

GetControlBar( _oid.m_nBarID )

);

 

|| ( pExtBar->IsFixedDockStyle() )

)

{

for( i = 0; i < arrOuterProps.GetSize(); i++ ) if( ( pExtBar->IsFixedMode() )

 

 

if(pExtBar == NULL)

continue;

if

|| ( pExtBar->IsFixedDockStyle() )

)

( ( pExtBar->IsFixedMode() ){

 


 
pExtBar is NULL as the toolbar no longer exists in the new build of the application. That is throwing an exception that seems to be caught later, but is seems to corrupt AfxActivateActCtx/AfxDeactivateActCtx state invariant that states that you can only deactivate something when it is the last thing to have been activated (top of the activation stack). That is in turn causing an exception to be thrown later on in our application’s lifetime (the next time AfxDeactivateActCtx is called). So, simply catching the NULL pointer exception still leaves the application in an inconsistent state.
Could a NULL check be added before pExtBar is dereferenced to avoid these problems? 

Technical Support Apr 8, 2010 - 9:58 AM

The NULL checking conditions were added into the CExtControlBar::InternalFriendlyFrameWnd::SetOuterDockState() method:

void CExtControlBar::InternalFriendlyFrameWnd::SetOuterDockState(
            const CDockState & state,
            const CExtControlBar::OuterPropsArr_t & arrOuterProps,
            bool bSerializeFixedBarsState,
            bool bSerializeResizableBarsState
            )
{
            // first pass through barinfo’s sets the m_pBar member correctly
            // creating floating frames if necessary
int i = 0;
            for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
            {
                        CControlBarInfo * pInfo = (CControlBarInfo *)
                                    state.m_arrBarInfo[i];
                        ASSERT( pInfo != NULL );
                        CControlBar * pExistingBar = GetControlBar( pInfo->m_nBarID );
                        if( pExistingBar != NULL )
                        {
                                    if(                     (! pExistingBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) )
                                                ||           ( ((CExtControlBar*)pExistingBar)->IsFixedMode() )
                                                ||           ( ((CExtControlBar*)pExistingBar)->IsFixedDockStyle() )
                                                )
                                    {
                                                if( ! bSerializeFixedBarsState )
                                                            continue;
                                    }
                                    else
                                    {
                                                if( ! bSerializeResizableBarsState )
                                                            continue;
                                    }
                        }
                        if( pInfo->m_bFloating )
                        {
                                    // need to create floating frame to match
                                    CMiniDockFrameWnd * pDockFrame =
                                                CreateFloatingFrame(
                                                            pInfo->m_bHorz ?
                                                                        CBRS_ALIGN_TOP : CBRS_ALIGN_LEFT
                                                            );
                                    ASSERT( pDockFrame != NULL) ;
                                    CRect rcWnd( pInfo->m_pointPos, CSize(10, 10) );
                                    pDockFrame->CalcWindowRect( &rcWnd );
                                    pDockFrame->SetWindowPos(
                                                NULL,
                                                rcWnd.left, rcWnd.top, 0, 0,
                                                SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE
                                                );
                                    CDockBar * pDockBar = (CDockBar *)
                                                pDockFrame->GetDlgItem( AFX_IDW_DOCKBAR_FLOAT );
                                    ASSERT( pDockBar != NULL );
                                    ASSERT_KINDOF( CDockBar, pDockBar );
                                    pInfo->m_pBar = pDockBar;
                        } // if( pInfo->m_bFloating )
                        else // regular dock bar or toolbar
                        {
                                    pInfo->m_pBar =
                                                pExistingBar; // GetControlBar( pInfo->m_nBarID );
                                    if( pInfo->m_pBar == NULL )
                                                continue;
                        } // else from if( pInfo->m_bFloating )
                        pInfo->m_pBar->m_nMRUWidth = pInfo->m_nMRUWidth;
            } // for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
            // update new outer props
            for( i = 0; i < arrOuterProps.GetSize(); i++ )
            {
                        OuterItemData_t _oid = arrOuterProps[i];
                        CControlBar * pBarTmp = GetControlBar( _oid.m_nBarID );
                        if( pBarTmp == NULL )
                                    continue;
                        CExtControlBar * pExtBar = DYNAMIC_DOWNCAST( CExtControlBar, pBarTmp );
                        if( pExtBar == NULL )
                                    continue;
                        if(                     ( pExtBar->IsFixedMode() )
                                    ||           ( pExtBar->IsFixedDockStyle() )
                                    )
                        {
                                    if( ! bSerializeFixedBarsState )
                                                continue;
                        }
                        else
                        {
                                    if( ! bSerializeResizableBarsState )
                                                continue;
                        }
                        pExtBar->m_ptFloatHelper = _oid.m_ptFloatHelper;
                        pExtBar->m_sizeDockedH = _oid.m_sizeDockedH;
                        pExtBar->m_sizeDockedV = _oid.m_sizeDockedV;
                        pExtBar->m_sizeFloated = _oid.m_sizeFloated;
                        pExtBar->_AffixmentSetOuter( &_oid.m_AffixmentData );
            } // for( i = 0; i < arrOuterProps.GetSize(); i++ )
            // the second pass will actually dock all of the control bars and
            // set everything correctly
            for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
            {
                        CControlBarInfo * pInfo = (CControlBarInfo *)
                                    state.m_arrBarInfo[i];
                        ASSERT( pInfo != NULL );
                        if( pInfo->m_pBar == NULL )
                                    continue;
                        if(                     (! pInfo->m_pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) )
                                    ||           ( ((CExtControlBar*)pInfo->m_pBar)->IsFixedMode() )
                                    ||           ( ((CExtControlBar*)pInfo->m_pBar)->IsFixedDockStyle() )
                                    )
                        {
                                    if( ! bSerializeFixedBarsState )
                                                continue;
                        }
                        else
                        {
                                    if( ! bSerializeResizableBarsState )
                                                continue;
                        }
                        if(                     pInfo->m_pBar->m_pDockContext != NULL
                                    &&        pInfo->m_pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar))
                                    )
                                    ((CExtControlBar*)(pInfo->m_pBar))->m_ptFloatHelper
                                                = pInfo->m_ptMRUFloatPos;
                        pInfo->m_pBar->SetBarInfo( pInfo, this );
            } // for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
            // the third pass will move independent floating bars
            // into valid positions
            for( i = 0; i < arrOuterProps.GetSize(); i++ )
            {
                        OuterItemData_t _oid = arrOuterProps[i];
                        CControlBar * pBarTmp = GetControlBar( _oid.m_nBarID );
                        if( pBarTmp == NULL )
                                    continue;
                        CExtControlBar * pExtBar = DYNAMIC_DOWNCAST( CExtControlBar, pBarTmp );
                        if( pExtBar == NULL )
                                    continue;
                        if(                     ( pExtBar->IsFixedMode() )
                                    ||           ( pExtBar->IsFixedDockStyle() )
                                    )
                        {
                                    if( ! bSerializeFixedBarsState )
                                                continue;
                        }
                        else
                        {
                                    if( ! bSerializeResizableBarsState )
                                                continue;
                        }
                        if( ! _oid.m_bFloating )
                                    continue;
                        CSize _sizeFloating = _oid.m_sizeFloated;
                        CRect rcFrameInitial( _oid.m_ptFloatHelper, _sizeFloating /*_oid.m_sizeFloated*/ );
                        CExtMiniDockFrameWnd * pMiniFrame =
                                    DYNAMIC_DOWNCAST(
                                                CExtMiniDockFrameWnd,
                                                pExtBar->GetParentFrame()
                                                );
                        CRect rcFrameNew =
                                    CExtPaintManager::stat_AlignWndRectToMonitor(
                                                rcFrameInitial
                                                );
                        if( pMiniFrame != NULL )
                        {
                                    ASSERT_VALID( pMiniFrame );
                                    CRect rcFrameReal;
                                    pMiniFrame->GetWindowRect( rcFrameReal );
                                    if( rcFrameReal.TopLeft() == rcFrameNew.TopLeft() )
                                    {
                                                pExtBar->DelayShow( _oid.m_bVisible ? TRUE : FALSE );
                                                pMiniFrame->RecalcLayout();
                                                continue;
                                    }
                                    pExtBar->OnNcAreaButtonsReinitialize();
                                    if( ! pExtBar->IsFixedMode() )
                                                pMiniFrame->ModifyStyle( FWS_SNAPTOBARS, 0 );
                                    pMiniFrame->MoveWindow( &rcFrameNew, FALSE );
                                    pMiniFrame->DelayRecalcLayout();
                                    if( _oid.m_bVisible )
                                    {
                                                pExtBar->DelayShow( TRUE );
                                                CSize _size = rcFrameNew.Size();
                                                pExtBar->SetInitDesiredSizeFloating( _size );
                                                pExtBar->m_pDockContext->m_sizeLast = _size;

                                                pMiniFrame->ShowWindow( SW_SHOWNOACTIVATE );
                                               pMiniFrame->MoveWindow( &rcFrameNew, FALSE );
                                                pMiniFrame->RecalcLayout();
                                                CRect rcClientFrame, rcWndFrame;
                                               pMiniFrame->GetClientRect( &rcClientFrame );
                                               pMiniFrame->GetWindowRect( &rcWndFrame );
                                                CRect rcClientBar, rcWndBar;
                                                pExtBar->GetClientRect( &rcClientBar );
                                                pExtBar->GetWindowRect( &rcWndBar );
                                                CSize _sizeBar =
                                                            _sizeFloating
                                                                        - rcClientFrame.Size()
                                                                        + rcWndFrame.Size()
                                                                        - rcClientBar.Size()
                                                                        + rcWndBar.Size()
                                                                        ;
                                                pExtBar->OnRepositionSingleChild(
                                                            _sizeBar.cx,
                                                            _sizeBar.cy,
                                                            true
                                                            );
                                    }
                        } // if( pMiniFrame != NULL )
                        else
                                    pExtBar->FloatControlBar( rcFrameNew.TopLeft() );
            } // for( i = 0; i < arrOuterProps.GetSize(); i++ )
            // last pass shows all the floating windows that were previously shown
            for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
            {
                        CControlBarInfo * pInfo = (CControlBarInfo *)
                                    state.m_arrBarInfo[i];
                        ASSERT( pInfo != NULL );
                        if( pInfo->m_pBar == NULL )
                                    continue;
                        if(                     (! pInfo->m_pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) )
                                    ||           ( ((CExtControlBar*)pInfo->m_pBar)->IsFixedMode() )
                                    ||           ( ((CExtControlBar*)pInfo->m_pBar)->IsFixedDockStyle() )
                                    )
                        {
                                    if( ! bSerializeFixedBarsState )
                                                continue;
                        }
                        else
                        {
                                    if( ! bSerializeResizableBarsState )
                                                continue;
                        }
                        if( ! pInfo->m_bFloating )
                                    continue;
                        CFrameWnd * pFrameWnd =
                                    pInfo->m_pBar->GetParentFrame();
                        CDockBar * pDockBar = (CDockBar *) pInfo->m_pBar;
                        ASSERT_KINDOF( CDockBar, pDockBar );
                        if( pDockBar->GetDockedVisibleCount() > 0 )
                        {
                                    pFrameWnd->RecalcLayout();
                                    pFrameWnd->ShowWindow( SW_SHOWNA );
                                    for( INT nBar = 1; nBar < pDockBar->m_arrBars.GetSize(); nBar ++ )
                                    {
                                                ASSERT( pDockBar->m_arrBars[0] == NULL );
                                                CControlBar * pBar = (CControlBar *)
                                                            pDockBar->m_arrBars[nBar];
                                                if( pBar == NULL )
                                                            continue;
                                                if( __PLACEHODLER_BAR_PTR(pBar) )
                                                            continue;
                                                CExtControlBar * pExtBar =
                                                            DYNAMIC_DOWNCAST(
                                                                        CExtControlBar,
                                                                        pBar
                                                                        );
                                                if( pExtBar == NULL
                                                            || pExtBar->IsFixedMode()
                                                            )
                                                            continue;
                                                pExtBar->_RecalcNcArea();
                                    }
                        } // if( pDockBar->GetDockedVisibleCount() > 0 )
            } // for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
}