Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTPPropertyGridItem::Remove causing Crash?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPPropertyGridItem::Remove causing Crash?

 Post Reply Post Reply
Author
Message
IRMark View Drop Down
Groupie
Groupie
Avatar

Joined: 13 July 2006
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote IRMark Quote  Post ReplyReply Direct Link To This Post Topic: CXTPPropertyGridItem::Remove causing Crash?
    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.


Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
IRMark View Drop Down
Groupie
Groupie
Avatar

Joined: 13 July 2006
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote IRMark Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
wolfgang6 View Drop Down
Newbie
Newbie


Joined: 13 November 2007
Location: Germany
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote wolfgang6 Quote  Post ReplyReply Direct Link To This Post 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().
 
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
IRMark View Drop Down
Groupie
Groupie
Avatar

Joined: 13 July 2006
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote IRMark Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
IRMark View Drop Down
Groupie
Groupie
Avatar

Joined: 13 July 2006
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote IRMark Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
wolfgang6 View Drop Down
Newbie
Newbie


Joined: 13 November 2007
Location: Germany
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote wolfgang6 Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
IRMark View Drop Down
Groupie
Groupie
Avatar

Joined: 13 July 2006
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote IRMark Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
wolfgang6 View Drop Down
Newbie
Newbie


Joined: 13 November 2007
Location: Germany
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote wolfgang6 Quote  Post ReplyReply Direct Link To This Post 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();
    }
}

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 515
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post Posted: 15 November 2007 at 9:28am
Hi,

second if (m_pGrid) can be removed.

    Jimmy

Back to Top
IRMark View Drop Down
Groupie
Groupie
Avatar

Joined: 13 July 2006
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote IRMark Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
wolfgang6 View Drop Down
Newbie
Newbie


Joined: 13 November 2007
Location: Germany
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote wolfgang6 Quote  Post ReplyReply Direct Link To This Post Posted: 16 November 2007 at 1:49am
It works in my code too, thank you.
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.188 seconds.