1
0
Fork 0
mutter-performance-source/cogl/tests/conform
Jonas Ådahl 7ddbcd1fd2 cogl/journal: Don't sometimes hold a ref on the framebuffer
d42f1873fc introduced a semi circular
reference between the CoglFramebuffer, and CoglJournal, where
CoglJournal would keep a reference on the CoglFramebuffer when there
were any entries in the journal log.

To avoid risking leaking these objects indefinitely, when freeing
objects without doing anything that triggered a flush, CoglFramebuffer
had a "filter" on cogl_object_unref() calls, which knew
about under what conditions CoglJournal had a reference to it. When it
could detect that there were only the journal itself holding such a
reference, it'd flush the journal, effectively releasing the reference
the journal held, thus freeing itself, as well as the journal.

When CoglFramebuffer was ported to be implemented using GObject instead
of CoglObject, this "filter" was missed, causing not only awkward but
infrequent leaks, but also situations where we'd flush journals when
only the journal itself held the last reference to the framebuffer,
meaning the journal would free the framebuffer, thus itself, in the
middle of flushing, causing memory corruption and crashes.

A way to detect this, by asserting on CoglObject reference count during
flush, is by adding the `g_assert()` as described below, which will
assert instead cause memory corruption.

void
_cogl_journal_flush (CoglJournal *journal
{
   ...
   _cogl_journal_discard (journal);
+  g_assert (journal->_parent.ref_count > 0);
   ...
}

Fix this by making CoglFramebuffer the owner of the journal, which it
already was, and remove any circle referencing that was there before, as
it is not needed given that the CoglFramebuffer pointer is guaranteed to
be valid for the lifetime of CoglJournal as the framebuffer is the owner
of the journal.

However, to not miss flushing before tearing down, which is important as
this flushes painting calls to the driver that is important for e.g.
using the result of those journal entries, flush the journal the first
time cogl_framebuffer_dispose() is called, before doing anything else.

This also adds a test case. Without having broken the circular
reference, the test would fail on g_assert_null (offscreen), as it would
have been "leaked" at this point, but the actual memory corruption would
be a result of the `cogl_texture_get_data()` call, which flushes the
framebuffer, and causes the 'mid-flush' destruction of the journal
described above. Note that the texture keeps track of dependent
framebuffers, but it does not hold any references to them.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1474
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1735>
2021-02-18 16:59:00 +00:00
..
meson cogl/tests: Export and run unit tests if they are enabled 2019-05-02 19:56:23 +00:00
meson.build cogl/journal: Don't sometimes hold a ref on the framebuffer 2021-02-18 16:59:00 +00:00
mutter-cogl.test.in Add Meson support for installed tests 2018-12-20 13:52:35 -02:00
test-alpha-test.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-alpha-textures.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-atlas-migration.c cogl tests: Force defined behaviour for 24-bit left-shifts 2020-05-27 21:26:49 +00:00
test-backface-culling.c cogl: Turn CoglFramebuffer, CoglOffscreen and CoglOnscreen into GObjects 2020-10-16 16:17:38 +00:00
test-blend-strings.c cogl/tests: Port away from legacy implicit stack based API 2019-12-03 19:02:14 +00:00
test-blend.c *: Fix spelling mistakes found by codespell 2020-08-29 09:10:31 +00:00
test-color-hsl.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-conform-main.c cogl/journal: Don't sometimes hold a ref on the framebuffer 2021-02-18 16:59:00 +00:00
test-copy-replace-texture.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-custom-attributes.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-declarations.h cogl/journal: Don't sometimes hold a ref on the framebuffer 2021-02-18 16:59:00 +00:00
test-depth-test.c cogl/tests: Port away from legacy implicit stack based API 2019-12-03 19:02:14 +00:00
test-fence.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-fixtures.c clutter/stage: Remove color property 2020-06-27 13:35:46 +00:00
test-framebuffer-get-bits.c cogl: Turn CoglFramebuffer, CoglOffscreen and CoglOnscreen into GObjects 2020-10-16 16:17:38 +00:00
test-journal.c cogl/journal: Don't sometimes hold a ref on the framebuffer 2021-02-18 16:59:00 +00:00
test-just-vertex-shader.c cogl: Remove no-op cogl_shader_compile and cogl_shader_get_info_log 2020-02-12 21:55:44 +00:00
test-layer-remove.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-map-buffer-range.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-multitexture.c *: Fix spelling mistakes found by codespell 2020-08-29 09:10:31 +00:00
test-no-gl-header.c move everything into a cogl/ directory 2016-04-22 16:44:31 +02:00
test-npot-texture.c cogl: NPOT textures are always available 2019-04-18 12:53:07 -04:00
test-object.c cogl: Remove CoglPath and the tesselator 2020-04-08 11:38:48 +02:00
test-offscreen.c cogl: Turn CoglFramebuffer, CoglOffscreen and CoglOnscreen into GObjects 2020-10-16 16:17:38 +00:00
test-pipeline-cache-unrefs-texture.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-pipeline-shader-state.c cogl: Turn CoglFramebuffer, CoglOffscreen and CoglOnscreen into GObjects 2020-10-16 16:17:38 +00:00
test-pipeline-uniforms.c cogl/tests: Use graphene APIs 2020-10-06 15:34:48 +00:00
test-pipeline-user-matrix.c cogl/tests: Use graphene APIs 2020-10-06 15:34:48 +00:00
test-pixel-buffer.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-point-size-attribute.c cogl: Remove CoglBool, use gboolean instead 2019-02-15 16:35:46 +01:00
test-point-size.c cogl: Remove CoglBool, use gboolean instead 2019-02-15 16:35:46 +01:00
test-point-sprite.c cogl: Remove CoglError wrapper 2019-06-20 18:25:04 +02:00
test-premult.c cogl test-premult: Don't free texture data until CoglBitmap is freed 2020-05-27 15:50:36 +01:00
test-primitive-and-journal.c cogl/tests: Use graphene APIs 2020-10-06 15:34:48 +00:00
test-primitive.c cogl: Remove CoglBool, use gboolean instead 2019-02-15 16:35:46 +01:00
test-read-texture-formats.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-readpixels.c tests: Use ClutterStage "after-paint" instead of ClutterActor "paint" 2020-10-23 22:06:58 +02:00
test-snippets.c cogl/tests: Use graphene APIs 2020-10-06 15:34:48 +00:00
test-sparse-pipeline.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-sub-texture.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-texture-get-set-data.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-texture-mipmaps.c *: Fix spelling mistakes found by codespell 2020-08-29 09:10:31 +00:00
test-texture-no-allocate.c cogl: Remove CoglError wrapper 2019-06-20 18:25:04 +02:00
test-texture-pixmap-x11.c tests: Use ClutterStage "after-paint" instead of ClutterActor "paint" 2020-10-23 22:06:58 +02:00
test-texture-rg.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-version.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00
test-viewport.c tests: Use ClutterStage "after-paint" instead of ClutterActor "paint" 2020-10-23 22:06:58 +02:00
test-wrap-modes.c cogl/tests: Port away from legacy implicit stack based API 2019-12-03 19:02:14 +00:00
test-write-texture-formats.c cogl: Add missing function declarations 2019-01-22 18:31:52 +01:00