gEDA-dev: pcb bug 1651335

DJ Delorie dj at delorie.com
Mon Mar 5 23:11:41 EST 2007


This is caused by the way I copy text from the old element to the new.

#0  backN_callback (b=0x8d36760, cl=0x0) at draw.c:260
#1  0x080ad274 in __r_search (node=0x8d047f0, query=0xbfb26ff0, arg=0xbfb26e40)
    at rtree.c:540
#2  0x080ad35c in r_search (rtree=0x8ab6380, query=0xbfb26e40, check_region=0, 
    found_rectangle=0x807e750 <backN_callback>, cl=0x0) at rtree.c:626
#3  0x0807fd75 in hid_expose_callback (hid=0x80fc5a0, region=0xbfb26ff0, item=0x0)
    at draw.c:430
#4  0x080c0334 in ghid_invalidate_all () at hid/gtk/gtkhid-main.c:260
#5  0x080804ec in Draw () at draw.c:198
#6  0x080a860c in RemoveElement (Element=0x8d36700) at remove.c:524
#7  0x0805cefa in NotifyMode () at action.c:1435
#8  0x0805da3d in ActionMode (argc=1, argv=0xbfb272c0, x=0, y=0) at action.c:2944

The code in question is attached.  Any suggestions on how to keep
things in sync during this transition?  The text has a pointer to the
element it belongs to, but that pointer is null.  If I don't zero out
the text items, the strings get freed.

    case PASTEBUFFER_MODE:
      {
	TextType estr[MAX_ELEMENTNAMES];
	ElementTypePtr e = 0;

	if (gui->shift_is_pressed ())
	  {
	    int type =
	      SearchScreen (Note.X, Note.Y, ELEMENT_TYPE, &ptr1, &ptr2,
			    &ptr3);
	    if (type == ELEMENT_TYPE)
	      {
		e = (ElementTypePtr) ptr1;
		if (e)
		  {
		    memcpy (estr, e->Name,
			    MAX_ELEMENTNAMES * sizeof (TextType));
		    memset (e->Name, 0, MAX_ELEMENTNAMES * sizeof (TextType));
		    RemoveElement (e);
		  }
	      }
	  }
	if (CopyPastebufferToLayout (Note.X, Note.Y))
	  SetChangedFlag (True);
	if (e)
	  {
	    int type =
	      SearchScreen (Note.X, Note.Y, ELEMENT_TYPE, &ptr1, &ptr2,
			    &ptr3);
	    if (type == ELEMENT_TYPE && ptr1)
	      {
		int i, save_n;
		e = (ElementTypePtr) ptr1;

		save_n = NAME_INDEX (PCB);

		for (i = 0; i < MAX_ELEMENTNAMES; i++)
		  {
		    if (i == save_n)
		      EraseElementName (e);
		    r_delete_entry (PCB->Data->name_tree[i],
				    (BoxType *) & (e->Name[i]));
		    memcpy (&(e->Name[i]), &(estr[i]), sizeof (TextType));
		    e->Name[i].Element = e;
		    SetTextBoundingBox (&PCB->Font, &(e->Name[i]));
		    r_insert_entry (PCB->Data->name_tree[i],
				    (BoxType *) & (e->Name[i]), 0);
		    if (i == save_n)
		      DrawElementName (e, 0);
		  }
	      }
	  }
	break;
      }


More information about the geda-dev mailing list