Re: Please help me debug




Anders Melchiorsen <and@kampsax.dtu.dk> writes:

> Hi, I have written this routine to show text. It displays quoted text
> in a different colour. What I would like to know is this: is the
> function correct? People have reported crashes to me, but I never see
> them, and I cannot see anything wrong with the function.
> 
> After the function is a backtrace of one of these crashes. It seems
> like it is the gtk_text_thaw() call at the end of the function that
> breaks it, but surely that line is correct, so it must be something
> else.
> 
> Users may have older versions, like 1.2.1 - have something been
> changed since then? That could explain me not seeing these problems.

A number of fixes to GtkText were made a month or so ago, and
this could have been one of them, if it doesn't happen for
you. GtkText is geneally buggy, so if you have crashes,
I'd tend to blame GtkText instead of your code.

Regards,
                                        Owen

> void gtk_text_set_buffer(GtkText* textarea, const char* buf)
> {
> 	// Show quoted text in a blue color
> 	GdkColor blueish;
> 	blueish.red   = 0;
> 	blueish.green = 0;
> 	blueish.blue  = 56000;
> 	GdkColor* qc = &blueish;
> 
> 	GdkColormap* colormap = gtk_widget_get_colormap(GTK_WIDGET(textarea));
> 	if (!gdk_colormap_alloc_color(colormap, qc, FALSE, TRUE))
> 		qc = 0;

You don't need to allocate the colors that you pass into the
Text widget.
 
> 	gtk_text_freeze(textarea);
> 	gtk_editable_delete_text(GTK_EDITABLE(textarea), 0,
> 				 gtk_text_get_length(textarea));

You could use -1 here instead of gtk_text_get_length().

> 	const char *at, *s;
> 	for (at = s = buf; *s; s = at) {
> 
> 		// Find end of this line
> 		while ((at[0]) && (at[0] != '\n'))
> 			++at;
> 
> 		// Add the found line to the text widget
> 		if (*s == '>')
> 			gtk_text_insert(textarea, 0, qc, 0, s, at-s);
> 		else
> 			gtk_text_insert(textarea, 0, 0, 0, s, at-s);
> 
> 		// If there was a newline, add it too
> 		if (at[0] == '\n') {
> 			gtk_text_insert(textarea, 0, 0, 0, "\n", 1);
> 			++at;
> 		}
> 	}
> 
> 	// gtk_text_insert() does not emit "changed" :-(
> 	gtk_editable_changed(GTK_EDITABLE(textarea));

Yes. "changed" basically indicates that the _user_ changed
the text.
 
> 	gtk_text_thaw(textarea);

> #0  0x40268111 in __kill ()
> #1  0x40267d66 in raise (sig=6) at ../sysdeps/posix/raise.c:27
> #2  0x40269447 in abort () at ../sysdeps/generic/abort.c:88
> #3  0x8095d54 in sig_handler (signum=11) at Main_common.cc:37
> #4  <signal handler called>
> #5  0x40068000 in draw_row ()
> #6  0x400dfbfd in gtk_text_adjustment ()
> #7  0x40104c9b in gtk_marshal_NONE__NONE ()

Could well be one of the bugs I fixed recently.

Regards,
                                        Owen



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