diff --git a/mediaportal/WindowPlugins/GUIPictures/GUISlidePicture.cs b/mediaportal/WindowPlugins/GUIPictures/GUISlidePicture.cs index ca0570f7e5b..0e64c9e5f03 100644 --- a/mediaportal/WindowPlugins/GUIPictures/GUISlidePicture.cs +++ b/mediaportal/WindowPlugins/GUIPictures/GUISlidePicture.cs @@ -26,7 +26,7 @@ #region SlidePicture class -internal class SlidePicture +internal class SlidePicture : IDisposable { private const int MAX_PICTURE_WIDTH = 2040; private const int MAX_PICTURE_HEIGHT = 2040; @@ -101,8 +101,17 @@ public SlidePicture(string strFilePath, bool useActualSizeTexture) { if (_texture != null && !_texture.IsDisposed) { - _texture.Dispose(); - _texture = null; + Log.Warn("[SlidePicture][dtor] Texture dispose call from dtor."); + this.Dispose(); + } + } + + public void Dispose() + { + if (this._texture != null && !this._texture.IsDisposed) + { + this._texture.Dispose(); + this._texture = null; } } } diff --git a/mediaportal/WindowPlugins/GUIPictures/GUISlideShow.cs b/mediaportal/WindowPlugins/GUIPictures/GUISlideShow.cs index b9bd65e6b57..e8ccb6469e6 100644 --- a/mediaportal/WindowPlugins/GUIPictures/GUISlideShow.cs +++ b/mediaportal/WindowPlugins/GUIPictures/GUISlideShow.cs @@ -1429,6 +1429,8 @@ public void Reset() { g_Player.Stop(); } + + this._slideCache.Clear(); } #endregion diff --git a/mediaportal/WindowPlugins/GUIPictures/SlideCache.cs b/mediaportal/WindowPlugins/GUIPictures/SlideCache.cs index ba4b30a9a45..4bb6c62955c 100644 --- a/mediaportal/WindowPlugins/GUIPictures/SlideCache.cs +++ b/mediaportal/WindowPlugins/GUIPictures/SlideCache.cs @@ -105,9 +105,15 @@ public SlidePicture GetCurrentSlide(string slideFilePath) { return PrevSlide; } - if (CurrentSlide != null && CurrentSlide.FilePath == slideFilePath) - { - return CurrentSlide; + if (CurrentSlide != null) + { + if (CurrentSlide.FilePath == slideFilePath) + return CurrentSlide; + else + { + CurrentSlide.Dispose(); + CurrentSlide = null; + } } // slide is not in cache, so get it now CurrentSlide = new SlidePicture(slideFilePath, false); @@ -131,14 +137,16 @@ public void PrefetchNextSlide(string prevPath, string currPath, string nextPath) { // shift slides and determine _neededSlideRelativeIndex if (NextSlide != null && NextSlide.FilePath == currPath) - { + { + PrevSlide?.Dispose(); PrevSlide = CurrentSlide; CurrentSlide = NextSlide; _neededSlideFilePath = nextPath; _neededSlideRelativeIndex = RelativeIndex.Next; } else if (PrevSlide != null && PrevSlide.FilePath == currPath) - { + { + NextSlide?.Dispose(); NextSlide = CurrentSlide; CurrentSlide = PrevSlide; _neededSlideFilePath = prevPath; @@ -206,7 +214,8 @@ public void InvalidateSlide(string slideFilePath) { SlidePicture slide = _slides[i]; if (slide != null && slide.FilePath == slideFilePath) - { + { + slide.Dispose(); _slides[i] = null; } } @@ -215,5 +224,22 @@ public void InvalidateSlide(string slideFilePath) // Note that we could pre-fetch the invalidated slide, but if the new version // of the slide is going to be requested immediately (as with DoRotate) then // pre-fetching won't help. + } + + public void Clear() + { + Log.Debug("[SlideCache] Clear()"); + lock (_slidesLock) + { + for (int i = 0; i < this._slides.Length; i++) + { + SlidePicture slide = this._slides[i]; + if (slide != null) + { + slide.Dispose(); + this._slides[i] = null; + } + } + } } } \ No newline at end of file