From f920fd8b6fe03354e36fa2f91f5175740f20f3ac Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 19 Mar 2013 15:26:05 -0400 Subject: [PATCH] background: properly disconnect background signals BackgroundManager connects to the changed signal in the backgrounds it manages. The signal ids for the changed signal connectionss are stored as state on the background manager object. If the background being managed changes while the manager is still loading the old background, then the signal id variable can get out of sync with the background object being managed. This commit ties the signal id to the background objects themselves, so there is no opportunity for them to desynchronize. https://bugzilla.gnome.org/show_bug.cgi?id=696157 --- js/ui/background.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/js/ui/background.js b/js/ui/background.js index e95cbc0a1..cacdffb0d 100644 --- a/js/ui/background.js +++ b/js/ui/background.js @@ -654,17 +654,9 @@ const BackgroundManager = new Lang.Class({ this.background = this._createBackground(); this._newBackground = null; - this._loadedSignalId = 0; - this._changedSignalId = 0; }, destroy: function() { - if (this._loadedSignalId) - this._newBackground.disconnect(this._loadedSignalId); - - if (this._changedSignalId) - this.background.disconnect(this._changedSignalId); - if (this._newBackground) { this._newBackground.actor.destroy(); this._newBackground = null; @@ -683,22 +675,24 @@ const BackgroundManager = new Lang.Class({ newBackground.saturation = background.saturation; newBackground.visible = background.visible; - let signalId = newBackground.connect('loaded', + newBackground.loadedSignalId = newBackground.connect('loaded', Lang.bind(this, function() { - newBackground.disconnect(signalId); + newBackground.disconnect(newBackground.loadedSignalId); + newBackground.loadedSignalId = 0; Tweener.addTween(background.actor, { opacity: 0, time: FADE_ANIMATION_TIME, transition: 'easeOutQuad', onComplete: Lang.bind(this, function() { - this.background = newBackground; - this._newBackground = null; - background.actor.destroy(); + if (this.background == background) { + this.background = newBackground; + this._newBackground = null; + background.actor.destroy(); + } this.emit('changed'); }) }); })); - this._loadedSignalId = signalId; this._newBackground = newBackground; }, @@ -717,12 +711,19 @@ const BackgroundManager = new Lang.Class({ background.actor.lower_bottom(); } - let signalId = background.connect('changed', Lang.bind(this, function() { - background.disconnect(signalId); + background.changeSignalId = background.connect('changed', Lang.bind(this, function() { + background.disconnect(background.changeSignalId); + background.changeSignalId = 0; this._updateBackground(background, this._monitorIndex); })); - this._changedSignalId = signalId; + background.actor.connect('destroy', Lang.bind(this, function() { + if (background.changeSignalId) + background.disconnect(background.changeSignalId); + + if (background.loadedSignalId) + background.disconnect(background.loadedSignalId); + })); return background; },