From 4ff3769a5746e06b58fd5fc26547def2f64ff05b Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Tue, 14 Jul 2015 16:53:49 +0100
Subject: [PATCH] Two unrelated bug fixes:

 - MaskOpts GLVolume hack needed to be updated to
   accommodate new VolumeOpts.invertClipping property.

 - HistogramSeries instances were being destroyed without deregistering
   their property listeners, and new ones created with the same memory
   address, so listener name collisions were occurring. They are now
   explicitly destroyed.
---
 fsl/fslview/displaycontext/maskopts.py | 22 +++++++++++++++-------
 fsl/fslview/views/histogrampanel.py    |  9 ++++++++-
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/fsl/fslview/displaycontext/maskopts.py b/fsl/fslview/displaycontext/maskopts.py
index f4f09345f..6616f4752 100644
--- a/fsl/fslview/displaycontext/maskopts.py
+++ b/fsl/fslview/displaycontext/maskopts.py
@@ -36,15 +36,23 @@ class MaskOpts(volumeopts.ImageOpts):
         dRangeLen    = abs(self.dataMax - self.dataMin)
         dMinDistance = dRangeLen / 10000.0
 
-        # This is a hack. Mask images are rendered
-        # using GLMask, which inherits from GLVolume.
-        # The latter assumes that 'clippingRange'
-        # and 'interpolation' attributes are present
-        # on Opts instances (see the VolumeOpts class).
+        #################
+        # This is a hack.
+        #################
+
+        # Mask images are rendered using GLMask, which
+        # inherits from GLVolume. The latter assumes
+        # that 'clippingRange', 'interpolation', and
+        # 'invertClipping' attributes are present on
+        # Opts instances (see the VolumeOpts class).
         # So we're adding dummy attributes to make the
         # GLVolume rendering code happy.
-        self.clippingRange = (self.dataMin - 1, self.dataMax + 1)
-        self.interpolation = 'none'
+        #
+        # TODO Write independent GLMask rendering routines
+        # instead of using the GLVolume implementations
+        self.clippingRange  = (self.dataMin - 1, self.dataMax + 1)
+        self.interpolation  = 'none'
+        self.invertClipping = False
 
         self.threshold.xmin = self.dataMin - dMinDistance
         self.threshold.xmax = self.dataMax + dMinDistance
diff --git a/fsl/fslview/views/histogrampanel.py b/fsl/fslview/views/histogrampanel.py
index 6bdc467dc..bb2dffa06 100644
--- a/fsl/fslview/views/histogrampanel.py
+++ b/fsl/fslview/views/histogrampanel.py
@@ -478,8 +478,15 @@ class HistogramPanel(plotpanel.PlotPanel):
 
     def __updateCurrent(self):
 
-        overlay        = self._displayCtx.getSelectedOverlay()
+        # Make sure that the previous HistogramSeries
+        # cleans up after itself, unless it has been
+        # cached
+        if self.__current is not None and \
+           self.__current not in self.__histCache.values():
+            self.__current.destroy()
+            
         self.__current = None
+        overlay        = self._displayCtx.getSelectedOverlay()
 
         if len(self._overlayList) == 0 or \
            not isinstance(overlay, fslimage.Image):
-- 
GitLab