Please help me debug




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.




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;

	gtk_text_freeze(textarea);
	gtk_editable_delete_text(GTK_EDITABLE(textarea), 0,
				 gtk_text_get_length(textarea));

	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));

	gtk_text_thaw(textarea);
}



...and the backtrace:


#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 ()
#8  0x400cc217 in gtk_handlers_run ()
#9  0x400cb70f in gtk_signal_real_emit ()
#10 0x400c9cf3 in gtk_signal_emit_by_name ()
#11 0x400e37e3 in scroll_int ()
#12 0x400e1ac2 in find_line_containing_point ()
#13 0x400e2067 in find_cursor ()
#14 0x400e540a in recompute_geometry ()
#15 0x400dd26e in gtk_text_thaw ()
#16 0x807a685 in gtk_text_set_buffer (textarea=0x80ff6a8, 
    buf=0x8133118 ">>>ESCAPE wrote: \n>>>3 dobbelt portion pandekager\n>>\n>>MYLIE wrote: \n>>er de færdige ?? og skal vi komme nu ??\n>ESCAPE wrote: \n>Nej nej, det klare jeg helt selv :) (ligesom igår)\nøv") at GUIfunctions.cc:138

(...more function calls followed...)


-- 
Mvh. Anders



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