GtkText bugs...




My editor widget seems to provoke a few bugs in the text widget (in
gtk 1.1).

These bugs appear event without the patch to gtktext currently needed
by the editor, so it is my hope, that some of you knows what to do, or
at least can point me in the direction for fixing the bugs.

The program attached catches two bugs, one with advance_mark and one
with undraw_cursor.

Run the program, and press F1, and it crashes down in flames.
Pressing F2 once works fine, but twice courses a crash.

F2, F1 => almost works but the colors (textproperties) are placed at
the wrong positions.

F2, F1, F2 => another crash.

The above crashes gives (with gdb):
#0  advance_mark (mark=0x44b08) at gtktext.c:2987
#1  0xef6d7010 in advance_mark_n (mark=0x44b08, n=3) at gtktext.c:2981
#2  0xef6d6f9c in move_mark_n (mark=0x44b08, n=3) at gtktext.c:2970
#3  0xef6d63ac in correct_cache_insert (text=0x333e0, nchars=3) at gtktext.c:2492
#4  0xef6d6574 in insert_expose (text=0x333e0, old_pixels=14, nchars=3, 
    new_line_count=1) at gtktext.c:2548
#5  0xef6d2348 in gtk_text_insert (text=0x333e0, font=0x23bd8, fore=0xefffe818, 
    back=0x31b88, chars=0x12090 "foo", nchars=3) at gtktext.c:805
#6  0x10f40 in argh1 ()

Pressing F3 once works right, twice crashes with:
#0  0xef6d9eb0 in undraw_cursor (text=0x333e0, absolute=0) at gtktext.c:4595
#1  0xef6d603c in delete_expose (text=0x333e0, nchars=14, old_lines=5, 
    old_pixels=70) at gtktext.c:2380
#2  0xef6d2724 in gtk_text_forward_delete (text=0x333e0, nchars=14)
    at gtktext.c:884
#3  0xef6d48cc in gtk_text_delete_text (editable=0x333e0, start_pos=14, 
    end_pos=28) at gtktext.c:1724
#4  0xef68ef1c in gtk_marshal_NONE__INT_INT (object=0x333e0, 
    func=0xef6d483c <gtk_text_delete_text>, func_data=0x0, args=0xefffe420)
    at gtkmarshal.c:281
#5  0xef6c2c4c in gtk_signal_real_emit (object=0x333e0, signal_id=61, 
    params=0xefffe420) at gtksignal.c:1423
#6  0xef6c044c in gtk_signal_emit (object=0x333e0, signal_id=61)
    at gtksignal.c:507
#7  0xef663470 in gtk_editable_delete_text (editable=0x333e0, start_pos=14, 
    end_pos=28) at gtkeditable.c:476
#8  0x110e4 in argh3 ()


I really hope you can help me fix this.

/mailund

===File ~/tmp/foo.c=========================================
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <stdlib.h>

/* replaces first 3 chars with foo on 1st line...not! */
static void
argh1 (GtkWidget *text)
{
  GdkColormap *cmap;
  GdkColor red;

  g_return_if_fail (gtk_text_get_length (GTK_TEXT (text)) > 3);

  /* stuff to make it crash */
  cmap = gtk_widget_get_colormap (text);
  red.red = 65535;
  red.green = 0;
  red.blue = 0;
  gdk_color_alloc (cmap, &red);

  gtk_editable_delete_text (GTK_EDITABLE (text), 0, 3);
  gtk_text_set_point (GTK_TEXT (text), 0);
  gtk_text_insert (GTK_TEXT (text), NULL, &red, NULL,
		   "foo", 3);
}

/* replaces first 3 chars with foo on 2nd line...not! */
static void
argh2 (GtkWidget *text)
{
  GdkColormap *cmap;
  GdkColor red;

  /* stuff to make it crash */
  cmap = gtk_widget_get_colormap (text);
  red.red = 65535;
  red.green = 0;
  red.blue = 0;
  gdk_color_alloc (cmap, &red);

  gtk_editable_delete_text (GTK_EDITABLE (text), 8, 11);
  gtk_text_set_point (GTK_TEXT (text), 8);
  gtk_text_insert (GTK_TEXT (text), NULL, &red, NULL,
		   "foo", 3);
}
/* change colors (alt. between red and green) on last lines...not! */
static void
argh3 (GtkWidget *text)
{
  GdkColormap *cmap;
  GdkColor red;
  GdkColor green;
  gchar *buf;
  static gboolean redp = TRUE;

  /* stuff to make it crash */
  cmap = gtk_widget_get_colormap (text);
  red.red = 65535;
  red.green = 0;
  red.blue = 0;
  green.red = 0;
  green.green = 65535;
  green.blue = 0;
  gdk_color_alloc (cmap, &red);
  gdk_color_alloc (cmap, &green);

  buf = gtk_editable_get_chars (GTK_EDITABLE (text), 14, 28);
  gtk_editable_delete_text (GTK_EDITABLE (text), 14, 28);
  gtk_text_set_point (GTK_TEXT (text), 14);
  gtk_text_insert (GTK_TEXT (text), NULL, redp ? &red : &green, NULL,
		   buf, 14);
  g_free (buf);
}

static gboolean
keypress (GtkWidget *text, GdkEventKey *ev)
{
  g_return_val_if_fail (text != NULL, FALSE);
  g_return_val_if_fail (ev != NULL, FALSE);

  switch (ev->keyval) {
  case GDK_F1:
    argh1 (text);
    break;
  case GDK_F2:
    argh2 (text);
    break;
  case GDK_F3:
    argh3 (text);
    break;
  }

  return FALSE;
}

int
main (int argc, char *argv[]) 
{
  GtkWidget *window;
  GtkWidget *text;
  
  /* initialize */
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Text Test");
  
  text = gtk_text_new (NULL, NULL);
  gtk_widget_show (text);
  gtk_text_set_editable (GTK_TEXT (text), TRUE);
  gtk_signal_connect (GTK_OBJECT (text), "key-press-event",
		      GTK_SIGNAL_FUNC (keypress), NULL);


  gtk_container_add (GTK_CONTAINER (window), text);
 
  /* show */
  gtk_widget_show (window);

  gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,
		   "This is\na test", 14);
  /*                         ^8 */
  gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,
		   "\n\nMore stuff\n\n", 14);
  /*                ^14           ^26^27 */

  /* main loop */
  gtk_main ();
 
  return EXIT_SUCCESS;
}
============================================================



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]