Skip to content

Commit

Permalink
Fix crash when repeatedly opening/closing GUI
Browse files Browse the repository at this point in the history
Cairo keeps a global cache list of connections, but since the reference
count of the device never reaches 0, the devices are never removed from
this cache list.

The crash happens when a new xcb_connection is made, and the new pointer
happens to be the same as an existing pointer in this cache list, then
the wrong cairo_xcb_connection is returned. Then no screen can be found,
since the root is not the same for that old xcb_connection and the new
one. Thus we end up at ASSERT_NOT_REACHED in _get_screen_index(), in
cairo-xcb-screen.c

Note that there is some resource leakage somewhere, since the reference
count of the cairo devices should reach 0 at some point, but never do.

Fixes steinbergmedia#334
  • Loading branch information
madah81pnz1 committed Jan 9, 2025
1 parent ad46cf6 commit 3a4b204
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions vstgui/lib/platform/linux/cairographicscontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ inline cairo_matrix_t convert (const TransformMatrix& ct)
struct CairoGraphicsDeviceFactory::Impl
{
std::vector<std::shared_ptr<CairoGraphicsDevice>> devices;
Impl() = default;
~Impl() noexcept
{
for (auto& device : devices)
{
#if DEBUG
DebugPrint ("Cairo device reference count: %u\n", cairo_device_get_reference_count (device->get ()));
#endif
// Force cairo to remove this device from its internal cache list of devices.
// This is only needed because the reference count never seem to reach 0,
// which means there is still some resource leakage elsewhere in the code.
cairo_device_finish (device->get ());
}
}
};

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 3a4b204

Please sign in to comment.