From ab135fa7c9bc21b87aec5c2e83dfd56bebb3761e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 23 Sep 2016 10:18:49 +0200 Subject: [PATCH] wibox.drawable: Don't redraw invalid drawables Twice now we had problems with the garbage collector which caused signals established via weak_connect_signal() not to be disconnected when we wanted them to be disconnected. The effect was that we tried to redraw a drawable after it was garbage collected which caused errors. Instead of playing whack-a-mole with all the various ways that might make us redraw a drawable after GC, let's just fix all of these issues by explicitly checking for this case and turning it into a no-op. Signed-off-by: Uli Schlachter --- lib/wibox/drawable.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index ef4953b3..e7df5821 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -60,7 +60,7 @@ local function get_widget_context(self) end local function do_redraw(self) - if type(self.drawable) ~= "drawable" then return end --FIXME See #1070 + if not self.drawable.valid then return end local surf = surface.load_silently(self.drawable.surface, false) -- The surface can be nil if the drawable's parent was already finalized @@ -400,6 +400,15 @@ function drawable.new(d, widget_context_skeleton, drawable_name) -- Set up our callbacks for repaints ret._redraw_callback = function(hierar, arg) + -- XXX: lgi will lead us into memory-corruption-land when we use an + -- object after it was GC'd. Try to detect this situation by checking if + -- the drawable is still valid. This is only a weak indication, but it + -- seems to be the best that we can do. The problem is that the drawable + -- could not yet be GC'd, but is pending finalisation, while the + -- cairo.Region below was already GC'd. This would still lead to corruption. + if not ret.drawable.valid then + return + end if ret._widget_hierarchy_callback_arg ~= arg then return end