Fixed memory leak caused by submarine preview images, changed Submarine.SavedSubmarines to a property that prevents removing submarines from outside the class without disposing the preview image. Closes #498

This commit is contained in:
Joonas Rikkonen
2018-07-18 14:23:43 +03:00
parent af4d60db1d
commit 568cf1a02f
9 changed files with 81 additions and 52 deletions
@@ -254,11 +254,14 @@ namespace Barotrauma
partial void DisposeTexture()
{
//check if another sprite is using the same texture
foreach (Sprite s in list)
if (!string.IsNullOrEmpty(file)) //file can be empty if the sprite is created directly from a Texture2D instance
{
if (s.file == file) return;
foreach (Sprite s in list)
{
if (s.file == file) return;
}
}
//if not, free the texture
if (texture != null)
{
@@ -267,6 +270,5 @@ namespace Barotrauma
}
}
}
}