![]()  | 
 
CXTPPropertyGridItem::Remove causing Crash? | 
 
    Post Reply  
   | 
  
| Author | |
   
   IRMark  
   
   Groupie  
   Joined: 13 July 2006 Status: Offline Points: 30  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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.  | 
 |
![]()  | 
 |
   
   Oleg  
   
   Senior Member  
   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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  | 
 |
![]()  | 
 |
   
   IRMark  
   
   Groupie  
   Joined: 13 July 2006 Status: Offline Points: 30  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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.  | 
 |
![]()  | 
 |
   
   Oleg  
   
   Senior Member  
   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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  | 
 |
![]()  | 
 |
   
   wolfgang6  
   
   Newbie  
   Joined: 13 November 2007 Location: Germany Status: Offline Points: 4  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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().  | 
 |
![]()  | 
 |
   
   Oleg  
   
   Senior Member  
   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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  | 
 |
![]()  | 
 |
   
   IRMark  
   
   Groupie  
   Joined: 13 July 2006 Status: Offline Points: 30  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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?  | 
 |
![]()  | 
 |
   
   Oleg  
   
   Senior Member  
   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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  | 
 |
![]()  | 
 |
   
   IRMark  
   
   Groupie  
   Joined: 13 July 2006 Status: Offline Points: 30  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     Posted: 13 November 2007 at 1:06pm | 
 
   
   
 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.  | 
 |
![]()  | 
 |
   
   Oleg  
   
   Senior Member  
   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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  | 
 |
![]()  | 
 |
   
   wolfgang6  
   
   Newbie  
   Joined: 13 November 2007 Location: Germany Status: Offline Points: 4  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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  | 
 |
![]()  | 
 |
   
   IRMark  
   
   Groupie  
   Joined: 13 July 2006 Status: Offline Points: 30  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     Posted: 14 November 2007 at 11:37am | 
 
   
   
 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.  | 
 |
![]()  | 
 |
   
   wolfgang6  
   
   Newbie  
   Joined: 13 November 2007 Location: Germany Status: Offline Points: 4  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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(); } }  | 
 |
![]()  | 
 |
   
   Oleg  
   
   Senior Member  
   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     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  | 
 |
![]()  | 
 |
   
   jimmy  
   
   Senior Member  
   Joined: 11 November 2003 Location: Austria Status: Offline Points: 516  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     Posted: 15 November 2007 at 9:28am | 
 
| 
   
    
   Hi, 
   
  second if (m_pGrid) can be removed. Jimmy  | 
 |
![]()  | 
 |
   
   IRMark  
   
   Groupie  
   Joined: 13 July 2006 Status: Offline Points: 30  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     Posted: 15 November 2007 at 2:16pm | 
 
   
   
 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.  | 
 |
![]()  | 
 |
   
   wolfgang6  
   
   Newbie  
   Joined: 13 November 2007 Location: Germany Status: Offline Points: 4  | 
  
   
      Post Options
    
        Thanks(0)
      Quote   Reply
   
     Posted: 16 November 2007 at 1:49am | 
 
| 
   
    
   It works in my code too, thank you.
    
   
   | 
 |
![]()  | 
 |
    Post Reply  
   | 
  |
|       
  
  Tweet   	
    | 
 
| Forum Jump | Forum Permissions  ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum  |