1

I've a problem with cairo_debug_reset_static_data() function when I combine both pango lib and cairo as I am getting the following assertion when its get called.

draw: cairo-hash.c:217: _cairo_hash_table_destroy: Assertion `hash_table->live_entries == 0' failed.

Here's the code I took from the following post: where some one had similar problem but they have not shared any working solution there(I already tried solution from the post, but it did not work). If we remove the commented lines then there is assertion.

#include <cairo.h>
#include <pango/pangocairo.h>

int
main (int argc, char *argv[])
{
    cairo_surface_t *surface;
    cairo_t *context;

    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 120, 120);
    context = cairo_create(surface);

    PangoRectangle extents;
    PangoLayout *layout;
    PangoFontDescription *desc;

    layout = pango_cairo_create_layout (context);

    desc = pango_font_description_from_string("Inconsolata 12");
    pango_layout_set_font_description(layout, desc);
    pango_font_description_free(desc);

    pango_layout_set_markup(layout, "hello", -1);
    //pango_layout_get_pixel_extents(layout, &extents, NULL);

    //pango_cairo_show_layout(context, layout);

    g_object_unref(layout);
    cairo_destroy(context);
    cairo_surface_destroy(surface);

    cairo_debug_reset_static_data();

    return(0);
}

I have tried to play around it to fix this problem, and also searched their documentation but could not find anything useful. Some one with expertise on pangocairo, please shed some light and point me to right direction.

Thanks

1 Answers1

0

Here's the code I took from the following post: where some one had similar problem but they have not shared any working solution there.

Well, did you see the reply to that post? It contains everything you need to know to fix this assertion failure:

Add a call to pango_cairo_font_map_set_default(NULL); before calling cairo_debug_reset_static_data();. That makes PangoCairo unreference the fonts that it still has alive.

Uli Schlachter
  • 9,337
  • 1
  • 23
  • 39
  • Thanks for the reply. I did as per the comments before posting here, but it did not fix it. – Dinesh Kumar Govinda Nov 18 '19 at 04:04
  • Just to be clear: You tried this solution and it does not work for you? For me and your example, it definitely works here... – Uli Schlachter Nov 18 '19 at 17:13
  • I see. Yeah, it did not work for me. Could you share how you tested it? Like OS, IDE, Compiler etc., and valgrind version, flags etc.,. I will try to rerun just like you. – Dinesh Kumar Govinda Nov 19 '19 at 05:33
  • Current Debian testing on amd64. I just compiled your example (with the two commented out lines added back in) with `gcc test.c $(pkg-config --cflags --libs pangocairo)`. This program dies with a failed assertion when run. Then I added a call to `pango_cairo_font_map_set_default(NULL);` right before the call to `cairo_debug_reset_static_data()`. When compiling & running the program again, it just exits normally. – Uli Schlachter Nov 19 '19 at 17:33
  • There is no valgrind involved for me and IDE... well, I use gVim as text editor. – Uli Schlachter Nov 19 '19 at 17:33
  • Ok, Thanks for the details.I will test again and see. – Dinesh Kumar Govinda Nov 22 '19 at 03:25