Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - CXTPStatusBar crash during RemoveALl
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPStatusBar crash during RemoveALl

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

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 886
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Topic: CXTPStatusBar crash during RemoveALl
    Posted: 21 October 2020 at 11:10am
We have added auto complete to an edit box we have on our status bar. Now we find that we can crash when calling SetIndicators. What is happening is that RemoveAll is looping over m_arrPanes and setting the m_pSutatusBar to null in the loop and then calling InternalRelease.

When InternalRelease is called, my CEdit control gets the expected DestroyWindow call. When the OS processes the window destruction call, the IAutoComplete object I have connected to the edit control is being decoupled and deep in the OS, the code dispatches WM_PAINT messages.

The status bar gets a WM_PAINT message and, to make a long story short this happens:

     ToolkitPro1930vc160x64UD.dll!CXTPStatusBar::GetPaintManager() Line 1125    C++
     ToolkitPro1930vc160x64UD.dll!CXTPStatusBar::GetStatusBarPaintManager() Line 1133    C++
     ToolkitPro1930vc160x64UD.dll!CXTPStatusBarPane::OnDraw(CDC * pDC=0x0000000000ded240, CRect rcItem={...}) Line 271    C++
     ToolkitPro1930vc160x64UD.dll!CXTPStatusBar::DrawPaneEntry(CDC * pDC=0x0000000000ded240, int nIndex=4, CRect rcItem={...}) Line 1144    C++
     ToolkitPro1930vc160x64UD.dll!CXTPStatusBar::OnDraw(CDC * pDC=0x0000000000ded240) Line 1218    C++
     ToolkitPro1930vc160x64UD.dll!CXTPStatusBar::OnPaint() Line 1151    C++

In OnDraw, the code loops thru the same array of CXTPStatusBarPane objects that are currently being released. The edit control pane is encountered and the OnDraw method is called and the code doesn't check to see that m_pStatusBar is now set to null by the RemoveAll code that is still executing.

We are seeing this with CJ 19.3 and Windows 10 1809 but it doesn't occur on all machines so may be somewhat OS dependent.

I added code in the edit control DestroyWindow call to PeekMessage and remove WM_PAINT (the OS dispatches the paint messages). That forces the paint to occur right away and I crash independent of the OS.

        CWnd* pParent = GetParent();
        if( pParent )
        {
            MSG    Msg;
            if( PeekMessage(  &Msg, pParent->GetSafeHwnd(), WM_PAINT,  WM_PAINT, PM_NOREMOVE|PM_NOYIELD ) )
            {
                TRACE("Found paint message for status bar");
                while (::PeekMessage(&Msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE))
                {
                }
            }
        }

It looks like I will be modifying CJ code to either test the status bar backpointer so it doesn't crash or to remove the item from the array before destroying it.

Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 886
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Posted: 21 October 2020 at 11:20am
While examining the status bar pane code, I see the code is inconsistent in testing the m_pStatusBar back pointer before using it. So, the code expects the pointer can be null in some places but not in other places.
Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 293
Post Options Post Options   Thanks (0) Thanks(0)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post Posted: 27 November 2020 at 3:35am
Hello,

Can I reproduce this bug with our sample?

Regards,
Artem Gontarenko
Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 293
Post Options Post Options   Thanks (0) Thanks(0)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post Posted: 08 December 2020 at 5:04am
Hello,

Could you please create a support ticket and attach a sample with a reproduced error.

Regards,
Artem Gontarenko
Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 293
Post Options Post Options   Thanks (0) Thanks(0)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post Posted: 21 April 2021 at 8:50am
Hello,

I am going to close this issue for now since I have not heard back from you. Please let me know if we need to re-open this issue at a later date.

Regards,
Artem Gontarenko
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 886
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Posted: 03 May 2021 at 12:36pm
Odd I didn't get any mail regarding replies to this. I believe I gave a very good description of the problem and the easy fix to just test your pointer in the code. Please do so as the call stack, whether you can duplicate it or not, doesn't lie and I was able to step right thru the code and see the null pointer access and subsequent crash.
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.156 seconds.