Print Page | Close Window

CXTPPropertyGridItem::Remove causing Crash?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=8735
Printed Date: 21 June 2024 at 1:28am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPPropertyGridItem::Remove causing Crash?
Posted By: IRMark
Subject: CXTPPropertyGridItem::Remove causing Crash?
Date Posted: 09 November 2007 at 11:35am
Hi,

I'm working with XTPro version 11.2.1 and we are experiencing a crash when we call the CXTPPropertyGridItem::Remove function.

Has anyone else had this problem?

The code that was giving us the crash is as follows:

CXTPPropertyGridItem* pSelected = m_wndGrid.GetSelectedItem();
if(!pSelected) return;
pSelected->Remove();


We were able to get around the issue using the following code based off of the CXTPPropertyGridItem::Remove() code but without the InternalRelease:

CXTPPropertyGridItem* pSelected = m_wndGrid.GetSelectedItem();
if(!pSelected) return;

CXTPPropertyGridItems* pItems = pSelected->GetParentItem()->GetChilds();
ASSERT(pItems);
int nIndex = pItems ? pItems->Find(pSelected) : -1;

if (nIndex != -1)
{
        pItems->RemoveAt(nIndex);
}


I think it may be the InernalRelase call the is causing the problem, since removing the CXTPPropertyGridItem item from CXTPPropertyGridItems seems to delete it?

Does anyone have any ideas? Is this a bug or am I doing something wrong?

Thanks.





Replies:
Posted By: Oleg
Date Posted: 09 November 2007 at 12:40pm
Hi,
Yes, it have to delete it. Do you create items dynamically like our sampls ?


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: IRMark
Date Posted: 09 November 2007 at 1:09pm
Hi Oleg we are creating the items like so:

CXTPPropertyGridItem* pItem =
            new CXTPPropertyGridItem(strName
            , strValue);


And then adding them to the Grid like so:

pCategory->InsertChildItem(i, pItem);

Where pCategory is a CXTPPropertyGridItem.

As I said in my previous post:

pSelected->Remove();

Used to work fine in previous versions of XtreeToolkit Pro, but now it appears to cause a crash.

Can you confirm that CXTPPropertyGridItem::Remove does not cause a crash?

After removing the item from the CXTPPropertyGridItems array is it safe to call InternalRelease?

pItems->m_arrItems.RemoveAt(nIndex);
InternalRelease();

This problem appears to be affecting more then one of our programs so I am interested in learning if it is a bug or a problem on our side.


Posted By: Oleg
Date Posted: 12 November 2007 at 1:16am
Him
 
Yes, its designed to call InternalRelease(); to free memory of item.
 
If you see crush, can you give call stack of it?


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: wolfgang6
Date Posted: 13 November 2007 at 6:50am
I've got the same problem. 
Version v11.2.1.
 
It is caused in CXTPPropertyGridItem::Remove()
 
m_pParent = NULL;
if (m_pGrid) m_pGrid->Refresh();
 
must be executed before InternalRelease() is invoked. This is because the "this" pointer becomes invalid in InternalRelease().
 


Posted By: Oleg
Date Posted: 13 November 2007 at 11:13am

damn, sorry, you right

 
IRMark, please replace pSelected->Remove(); line in your code with
 
pSelected->InternalAddRef();
pSelected->Remove();
pSelected->InternalRelease();


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: IRMark
Date Posted: 13 November 2007 at 11:36am
Hi,

Thanks wolfgang6, I was going to post that, but I didn't have a chance and thanks Oleg for finding a workaround.

I'm assuming that in future versions this will be fixed?


Posted By: Oleg
Date Posted: 13 November 2007 at 1:00pm
Hi,
Yes, think we will release  some 11.2.2 with this fix.
Thnks for point this bug.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: IRMark
Date Posted: 13 November 2007 at 1:06pm
Originally posted by oleg oleg wrote:

Yes, think we will release  some 11.2.2 with this fix.
Thnks for point this bug.


No Problem Oleg, any idea when 11.2.2 will be released? We have a release coming up so I'm just trying to decide if I want to use your workaround or if I should hold off for the new version.


Posted By: Oleg
Date Posted: 14 November 2007 at 12:59am
Hello,
 
There are not much changes for 11.2.2 for now, so I not sure. Think best slution for you is patch our sources and move InternalRelease to the bottom.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: wolfgang6
Date Posted: 14 November 2007 at 7:07am

It's a great feeling to help the gurus ;-)

 

Solving the problem we discussed above did not solve all the problems in my code. I'm updating from version 10.3.1. Please take a look:

 

class CMyPropGrid : public CXTPPropertyGrid {...}

 

BOOL CMyPropGrid::Create(const RECT& rect, CWnd* pParentWnd, UINT nID, DWORD dwListStyle) {

  CXTPPropertyGrid::Create(rect, pParentWnd, nID, dwListStyle);

  CXTPPropertyGridItem* pgitDummy = CreateItem(_T("dummy"), _T(""));

  CXTPPropertyGridItem* pgitDummyCat = AddCategory(_T("DUMMY-CAT"));

  pgitDummyCat->AddChildItem(pgitDummy);

  //...compute the grid height for x rows using heigth of pigtDummy

  pgitDummy->Remove(); // !

  pgitDummyCat->Remove(); // !

  //...

  ResetContent();

  //...

}

 

With 12.2.1, I have to skip pgitDummy->Remove() or pgitDummyCat->Remove() or both. Otherwise CXTPPropertyGridView::ResetContent() runs into a memory fault at pItem->SetVisible(FALSE); pItem == pguitDummyCat at this time.

 

Regards

Wolfgang



Posted By: IRMark
Date Posted: 14 November 2007 at 11:37am
Originally posted by oleg oleg wrote:

Hello,
 
There are not much changes for 11.2.2 for now, so I not sure. Think best slution for you is patch our sources and move InternalRelease to the bottom.


Hi,

We have also tried patching the code as follows:

// Deletes the item.
void CXTPPropertyGridItem::Remove()
{
    if (!m_pGrid)
        return;

    CXTPPropertyGridItems* pItems = GetParentItem() == 0 ? m_pGrid->m_pCategories : GetParentItem()->m_pChilds;
    ASSERT(pItems);
    int nIndex = pItems ? pItems->Find(this) : -1;

    if (nIndex != -1)
    {
        m_pParent = NULL;
        if (m_pGrid) m_pGrid->Refresh();
        pItems->m_arrItems.RemoveAt(nIndex);
        InternalRelease();
    }
}

But this does not seem to solve the problem either, and we have continued to experience a crash.

This is a serious issue for us as we have spent a lot of time on it, and are approaching the release of our software.



Posted By: wolfgang6
Date Posted: 15 November 2007 at 6:28am
It should look like this:

// Deletes the item.
void CXTPPropertyGridItem::Remove()
{
    if (!m_pGrid)
        return;

    CXTPPropertyGridItems* pItems = GetParentItem() == 0 ? m_pGrid->m_pCategories : GetParentItem()->m_pChilds;
    ASSERT(pItems);
    int nIndex = pItems ? pItems->Find(this) : -1;

        m_pParent = NULL;
        if (m_pGrid) m_pGrid->Refresh();

    if (nIndex != -1)
    {
        pItems->m_arrItems.RemoveAt(nIndex);
        InternalRelease();
    }
}



Posted By: Oleg
Date Posted: 15 November 2007 at 8:39am
Here what we changed:
 
void CXTPPropertyGridItem::Remove()
{
 if (!m_pGrid)
  return;
 CXTPPropertyGridItems* pItems = GetParentItem() == 0 ? m_pGrid->m_pCategories : GetParentItem()->m_pChilds;
 ASSERT(pItems);
 int nIndex = pItems ? pItems->Find(this) : -1;
 if (nIndex == -1)
  return;
 pItems->m_arrItems.RemoveAt(nIndex);
 m_pParent = NULL;
 if (m_pGrid) m_pGrid->Refresh();
 InternalRelease();
}


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: jimmy
Date Posted: 15 November 2007 at 9:28am
Hi,

second if (m_pGrid) can be removed.

    Jimmy



Posted By: IRMark
Date Posted: 15 November 2007 at 2:16pm
Originally posted by oleg oleg wrote:

Here what we changed:
...


Thanks Oleg, that one worked for us. I guess InternalRelease() has to be the very very (not even in an if statement) line in the function.

Also nice point jimmy.



Posted By: wolfgang6
Date Posted: 16 November 2007 at 1:49am
It works in my code too, thank you.



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