diff --git a/fsl/fsleyes/gl/lightboxcanvas.py b/fsl/fsleyes/gl/lightboxcanvas.py index 7a635279cd950abc324043eb44775c40baacb619..5f6b21d319f51ab253e79f626ee1e8381b47da74 100644 --- a/fsl/fsleyes/gl/lightboxcanvas.py +++ b/fsl/fsleyes/gl/lightboxcanvas.py @@ -741,6 +741,15 @@ class LightBoxCanvas(slicecanvas.SliceCanvas): if not self._setGLContext(): return + overlays = self.displayCtx.getOrderedOverlays() + globjs = [self._glObjects.get(o, None) for o in overlays] + globjs = [g for g in globjs if g is not None] + + # Skip the render if any GLObjects are not + # ready - see comments in SliceCanvas._draw. + if any([not g.ready() for g in globjs]): + return + if self.renderMode == 'offscreen': log.debug('Rendering to off-screen texture') @@ -770,12 +779,12 @@ class LightBoxCanvas(slicecanvas.SliceCanvas): endSlice = self._nslices # Draw all the slices for all the overlays. - for overlay in self.displayCtx.getOrderedOverlays(): + for overlay, globj in zip(overlays, globjs): display = self.displayCtx.getDisplay(overlay) globj = self._glObjects.get(overlay, None) - if (globj is None) or (not globj.ready()) or (not display.enabled): + if not display.enabled: continue log.debug('Drawing {} slices ({} - {}) for ' diff --git a/fsl/fsleyes/gl/slicecanvas.py b/fsl/fsleyes/gl/slicecanvas.py index 08068e11dc54dd3064ac495113b9c15ff794a75e..e708354f59e3a7dcf98c908e2244c4e427fc6404 100644 --- a/fsl/fsleyes/gl/slicecanvas.py +++ b/fsl/fsleyes/gl/slicecanvas.py @@ -1202,31 +1202,38 @@ class SliceCanvas(props.HasProperties): if not self._setGLContext(): return + overlays = self.displayCtx.getOrderedOverlays() + globjs = [self._glObjects.get(o, None) for o in overlays] + + # If an overlay does not yet have a corresponding + # GLObject, we presume that it hasn't been created + # yet (and that the __genGLObject method is on the + # case). + globjs = [g for g in globjs if g is not None] + + # Do not draw anything if some globjects + # are not ready. This is because, if a + # GLObject was drawn, but is now temporarily + # not ready (e.g. it has an image texture + # that is being asynchronously refreshed), + # drawing the scene now would cause + # flickering of that GLObject. + if any([not g.ready() for g in globjs]): + return + # Set the viewport to match the current # display bounds and canvas size if self.renderMode is not 'offscreen': self._setViewport() glroutines.clear(self.bgColour) - for overlay in self.displayCtx.getOrderedOverlays(): + for overlay, globj in zip(overlays, globjs): display = self.displayCtx.getDisplay(overlay) opts = display.getDisplayOpts() - globj = self._glObjects.get(overlay, None) if not display.enabled: continue - - if globj is None: - # The GLObject has not been created - # yet - we assume here that the - # __genGLObject method is on the case - continue - - # The GLObject is not ready - # to be drawn yet. - if not globj.ready(): - continue # On-screen rendering - the globject is # rendered directly to the screen canvas