Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP1-5232: GUISlideShow: Fix GPU memory leak #355

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
}
}
Loading