Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - PtTree instability: (5 Items)
   
PtTree instability  
I have a PtTree with a PtDivider to use two columns. I am currently trying to use no images. In a separate dialog, I 
have PtText widgets to edit the names of some of the tree items. Whenever the PtText widgets are updated 
(Pt_CB_MODIFY_NOTIFY), I call

   PtTreeChangeItem(tree, item, newname, NULL);

to update the tree text. Before long (after 4 or 5 updates) I get a SIGSEGV from within PtTreeChangeItem():

  32 _list_release()  0xb0327324	
  31 __prelocked_free()  0xb0328b0e	
  30 __free()  0xb0328c79	
  29 free()  0xb0325b1d	
  28 __realloc()  0xb0328879	
  27 realloc()  0xb0325bf4	
  26 PtGenListItemRealloc()  0xb826f0d1	
  25 PtGenTreeItemRealloc()  0xb8277f1a	
  24 tree_setstring()  0xb82d2058	
  23 PtTreeChangeItem()  0xb82d2101	

The tree items are created with:

  TreeItem = PtTreeAllocItem(ABW_Graphs_Tab, temp_buf, -1, -1);

The documentation for PtTreeChangeItem is vague as to the implications of passing in a NULL for the attributes argument.
 It says:

  Set to NULL to display no images, and use the widget-defined font and
  colors. The Pt_TREE_ITEM_HAS_ATTRS flag bit is still set for the item.

What are the implications of having Pt_TREE_ITEM_HAS_ATTRS set, particularly if no attrs have been supplied? Is it 
possible that the library is attempting to dereference the attribute pointer or free it?
Re: PtTree instability  
Based on your snippet and the backtrace -- your are trying to free an item that is already freed. The PtTreeChangeItem()
 may return a new item that you have to maintain. Your code should like this:

new_item = PtTreeChangeItem(tree, item, newname, NULL);
if( new_item != null ) {
item = new_item;
} else {
// TODO: Handle this error!
}

Regards,
-Misha.

Re: PtTree instability  
Ah, that would do it!

Misha Nefedov wrote:
> Based on your snippet and the backtrace -- your are trying to free an item that is already freed. The 
PtTreeChangeItem() may return a new item that you have to maintain. Your code should like this:
>
> new_item = PtTreeChangeItem(tree, item, newname, NULL);
> if( new_item != null ) {
> item = new_item;
> } else {
> // TODO: Handle this error!
> }
>
> Regards,
> -Misha.
>
>
>
> _______________________________________________
> QNX Momentics Community Support
> http://community.qnx.com/sf/go/post27780
>   
Re: PtTree instability  
Yes, thanks. That resolved it. That little fact rather escaped me in the documentation. I'm glad I managed to get enough
 context into the post for you to see the problem. I'm sure looking forward to seeing the Photon source code!
Re: PtTree instability  
Thanks for posting Norton. I'll see that the docs get updated accordingly.