Is font face reference counting broken?

Uli Schlachter psychon at znc.in
Thu May 16 15:11:12 UTC 2024


Am 15.05.24 um 21:48 schrieb Carl Worth:
> On Wed, May 15 2024, Uli Schlachter wrote:
>> Ah, okay. I was thinking about a long-running program. There, newer
>> fonts would eventually cause the old, stale ones to be evicted from the
>> cache. At that point, the callback would be called.
>>
>> In such a situation, using cairo_debug_reset_static_data() could be
>> problematic, because "something else" could still be having cairo
>> objects alive.
> 
> FWIW, I don't think it would be problematic. If "something else" still
> has cairo objects alive, then that something else will also have
> reference counts for that.

Yeah, and those references trigger assertions in cairo.

Running the following program:

#include <cairo.h>

int main() {
	cairo_t *cr = 
cairo_create(cairo_image_surface_create(CAIRO_FORMAT_RGB24, 1, 1));
	cairo_show_text(cr, "Cause some font stuff to initialise");
	cairo_debug_reset_static_data();
	return 0;
}

produces the following output for me:

a.out: ../../../src/cairo-hash.c:217: _cairo_hash_table_destroy: 
Assertion `hash_table->live_entries == 0' failed.

The backtrace goes like this:

- main calls
- cairo_debug_reset_static_data() calls
- _cairo_scaled_font_map_destroy() calls
- _cairo_hash_table_destroy(_cairo_scaled_font_map->hash_table)

_cairo_hash_table_destroy() does:
    assert(hash_table->live_entries == 0);

This assertion fails and sadness follows.

If I change the example to destroy the cairo context and the surface 
before calling cairo_debug_reset_static_data(), everything is fine.

Cheers,
Uli
-- 
- Buck, when, exactly, did you lose your mind?
- Three months ago. I woke up one morning married to a pineapple.
   An ugly pineapple... But I loved her.



More information about the cairo mailing list