Search code examples
multithreadingpython-2.7gtkcritical-sectionpango

Extremely Random Pango Crashes


As the title says, I've been running over some weird crashes, apparently caused by Pango or related.

My program works correctly, does everything on time, no weird visual glitches or errors of any other kind, BUT this kind of errors lead, usually, to a crash. Sometimes it just throws an exception and continues, but approximately 10% of those exceptions end in a crash, without mentioning I have no idea of what could be causing it.

Here are some logs of different attempts:

The most common one:

(App:23224): Pango-CRITICAL **: pango_layout_set_width: assertion 'layout != NULL' failed

(App:23224): Pango-CRITICAL **: pango_layout_get_width: assertion 'layout != NULL' failed

(App:23224): Pango-CRITICAL **: pango_layout_get_extents: assertion 'layout != NULL' failed

(App:23224): Pango-CRITICAL **: pango_layout_is_wrapped: assertion 'layout != NULL' failed

(App:23224): Pango-CRITICAL **: pango_layout_is_ellipsized: assertion 'layout != NULL' failed
./Def:822: Warning: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
  Gtk.main()

(App:23224): Pango-CRITICAL **: pango_layout_get_extents: assertion 'layout != NULL' failed

The more-or-less common one...

(App:22385): Pango-CRITICAL **: pango_layout_is_wrapped: assertion 'layout != NULL' failed

(App:22385): Pango-CRITICAL **: pango_layout_is_ellipsized: assertion 'layout != NULL' failed
./Def:820: Warning: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
  Gtk.main()

(App:22385): Pango-CRITICAL **: pango_layout_get_extents: assertion 'layout != NULL' failed

And the weirdest of all:

Pango:ERROR:/build/buildd/pango1.0-1.36.3/./pango/pango-layout.c:3916:pango_layout_check_lines: assertion failed: (!layout->log_attrs)

The last one has been only seen 1 time, the rest of errors are kind of common.

Ironically, the last one appeared when my App was still alive for record time, and then this error ended it suddenly, without even the "common" errors...

Any ideas what could be happening?

As I've said before, my app works as it should until one of the above errors end it.

More Info:

  1. My app is multi-threaded, but this error doesn't seem to be related to threads...otherwise something else should complain too!

Solution

  • Well, after a quite long research, I did found This, This and This.

    All of 'em were useful. The first one it's a link to another SO's question about the same topic, the second one it's a link to official GNOME's website for devs, were I found info about a curious Gdk function: Gdk.threads_add_idle, and the third one it's a link to a bug report from the aforementioned Gdk function, because in Python it asks for 3 args, when in C asks just for 2, but there it clarifies why it asks for 3.

    It wasn't too difficult to fix this after I discovered Gdk.threads_add_idle.

    I just had to move all my calls to Gtk to functions and, in the second thread, change all those calls with Gdk.threads_add_idle(priority, function, data), where priority should be GLib.PRIORITY_DEFAULT_IDLE and function must be the function containing all calls to Gtk.

    data it's an optional argument. It shall contain all additional data that you would like to pass to function