Print Page | Close Window

CXTPStatusBar crash during RemoveALl

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=24083
Printed Date: 21 November 2024 at 8:54pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPStatusBar crash during RemoveALl
Posted By: rdhd
Subject: CXTPStatusBar crash during RemoveALl
Date 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.




Replies:
Posted By: rdhd
Date 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.


Posted By: agontarenko
Date Posted: 27 November 2020 at 3:35am
Hello,

Can I reproduce this bug with our sample?

Regards,
Artem Gontarenko


Posted By: agontarenko
Date 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


Posted By: agontarenko
Date 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


Posted By: rdhd
Date 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.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net