Skip to content

Commit

Permalink
MP1-5232: GUISlideShow: Fix GPU memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
epbk committed Jan 12, 2025
1 parent 4d6b455 commit 31a8923
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
15 changes: 12 additions & 3 deletions mediaportal/WindowPlugins/GUIPictures/GUISlidePicture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions mediaportal/WindowPlugins/GUIPictures/GUISlideShow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,8 @@ public void Reset()
{
g_Player.Stop();
}

this._slideCache.Clear();
}

#endregion
Expand Down
38 changes: 32 additions & 6 deletions mediaportal/WindowPlugins/GUIPictures/SlideCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -206,7 +214,8 @@ public void InvalidateSlide(string slideFilePath)
{
SlidePicture slide = _slides[i];
if (slide != null && slide.FilePath == slideFilePath)
{
{
slide.Dispose();
_slides[i] = null;
}
}
Expand All @@ -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;
}
}
}
}
}

0 comments on commit 31a8923

Please sign in to comment.