Assertion CRITICAL failed

My Gtk3 program works, just fine. However, I get these critical Gtk messages when the program runs. I have hacked around speculatively changing assertions to no effect. I have, of course searched the web for answers. A code fragment follows which (I think) is causing the messages. The Gtk3 is hand coded, no Glade.

How should I go about debugging this type of message ?

(Kollwitz:144526): Gtk-CRITICAL **: 15:22:53.814: gtk_text_buffer_insert_at_cursor: 
assertion 'GTK_IS_TEXT_BUFFER (buffer)' failed

(Kollwitz:144526): Gtk-CRITICAL **: 15:22:53.814: gtk_text_buffer_get_insert: a
ssertion 'GTK_IS_TEXT_BUFFER (buffer)' failed

(Kollwitz:144526): Gtk-CRITICAL **: 15:22:53.814: gtk_text_view_scroll_mark_onscreen: 
assertion 'GTK_IS_TEXT_VIEW (text_view)' failed

(Kollwitz:144526): Gtk-CRITICAL **: 15:22:53.814: gtk_text_view_get_buffer: 
assertion 'GTK_IS_TEXT_VIEW (text_view)' failed
GtkWidget *install_console(int width, int height, GtkWidget **console_text_view)
	GtkWidget *scroll_window;
	GtkTextBuffer *console_buffer;
	PangoFontDescription *font;
	GdkRGBA rgba;

	scroll_window = gtk_scrolled_window_new(NULL, NULL);
	gtk_container_set_border_width(GTK_CONTAINER(scroll_window), 5);
	gtk_widget_set_size_request(scroll_window, width, height);

	*console_text_view = gtk_text_view_new();
	gtk_container_add(GTK_CONTAINER(scroll_window), *console_text_view);

	font = pango_font_description_from_string("Monospace 8");
	gtk_widget_override_font(*console_text_view, font);

	console_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(*console_text_view));

	// Change default color throughout the widget
	gdk_rgba_parse (&rgba, "blue");
	gtk_widget_override_color(*console_text_view, GTK_STATE_FLAG_NORMAL, &rgba);

	gtk_text_buffer_insert_at_cursor(console_buffer, "", -1);

	return scroll_window;

void gui_console_printf(GtkWidget **console_text_view, const char *control, ...)
	va_list parms;
	GtkTextBuffer *console_buffer;
	GtkTextMark *console_mark;
	char text[TEXT_BUFFER_SIZE];

	va_start(parms, control);
	vsnprintf(text, TEXT_BUFFER_SIZE, control, parms);
	printf("%s", text);
	console_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(*console_text_view));
	gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(console_buffer), text, -1);
	console_mark = gtk_text_buffer_get_insert(GTK_TEXT_BUFFER(console_buffer));
	gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(*console_text_view), console_mark);

You can set the environment variable G_DEBUG=fatal-criticals (or even G_DEBUG=fatal-warnings if you want) to let glib abort on critical (or warnings) log messages, so you can run your program with a debugger which should stop when it aborts after the log message was printed, so you can look into where this occurs (and what the variables are).

1 Like

Well, I set the environment variable:
export G_DEBUG=fatal-criticals|
and checked it was set but the messages are exactly the same.

You may think me fussy, because the application runs just fine, but I hate warnings like this. In fact it isn’t a warning the messages say an assertion failed.

The G_DEBUG=fatal-criticals environment variable does not change the warnings: it makes them fatal.

What you’re supposed to do is to run the application under GDB to get a backtrace at the time the warning is emitted. See the handbook and the GLib documentation.

The critical warnings you’re getting are emitted by the precondition checks for the gtk_text_buffer_insert_at_cursor() and friends: some code is passing an invalid pointer to those functions, where they are expecting a pointer to a GtkTextBuffer instance.

Hello Emmanuele,
The IDE I use runs my code under GDB. My program doesn’t crash and so there is no stack trace. All I get are messages that are “Critical” yet the application runs fine. If there were an uninitialized pointer I figure things would crash and the IDE’s invocation of GDB would give me a stack trace.

All the pointers, in the two functions I show, are initialized by Gtk.

Should I build the program with some debug flags turned on for Gtk ? I’m just using $(shell pkg-config --cflags gtk±3.0)

If the application runs without aborting then it means it’s not getting G_DEBUG injected in its environment. Make sure you have configured the running environment correctly.

Oh dear. This puts me debugging the debugging. The environment variable seems to be in place.

I think I’ll stub out functions until the messages go away and narrow down things that way.