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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-09-23 10:18:49 +02:00
parent 489aa4dc24
commit ab135fa7c9
1 changed files with 10 additions and 1 deletions

View File

@ -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