(2c4d0cf44) Fixed memorystream not being disposed when saving a submarine preview image

This commit is contained in:
Joonas Rikkonen
2019-04-05 16:14:26 +03:00
parent 1db710b92b
commit 7dae8639cc
2 changed files with 42 additions and 4 deletions

View File

@@ -66,6 +66,33 @@ namespace Barotrauma
CanBeFocused = false
};
Point scrollButtonSize = new Point((int)(200 * GUI.Scale), (int)(30 * GUI.Scale));
crewArea = new GUIFrame(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.CrewArea, guiFrame.RectTransform), "", Color.Transparent)
{
CanBeFocused = false
};
toggleCrewButton = new GUIButton(new RectTransform(new Point((int)(30 * GUI.Scale), HUDLayoutSettings.CrewArea.Height), guiFrame.RectTransform)
{ AbsoluteOffset = HUDLayoutSettings.CrewArea.Location },
"", style: "UIToggleButton");
toggleCrewButton.OnClicked += (GUIButton btn, object userdata) =>
{
toggleCrewAreaOpen = !toggleCrewAreaOpen;
foreach (GUIComponent child in btn.Children)
{
child.SpriteEffects = toggleCrewAreaOpen ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
}
return true;
};
characterListBox = new GUIListBox(new RectTransform(new Point(100, (int)(crewArea.Rect.Height - scrollButtonSize.Y * 1.6f)), crewArea.RectTransform, Anchor.CenterLeft), false, Color.Transparent, null)
{
//Spacing = (int)(3 * GUI.Scale),
ScrollBarEnabled = false,
ScrollBarVisible = false,
CanBeFocused = false
};
var characterInfo = new CharacterInfo(subElement);
characterInfos.Add(characterInfo);
foreach (XElement invElement in subElement.Elements())
@@ -81,6 +108,16 @@ namespace Barotrauma
prevUIScale = GUI.Scale;
}
#endregion
#region Character list management
public Rectangle GetCharacterListArea()
{
return characterListBox.Rect;
}
partial void InitProjectSpecific()
{
guiFrame = new GUIFrame(new RectTransform(Vector2.One, GUICanvas.Instance), null, Color.Transparent)

View File

@@ -840,10 +840,11 @@ namespace Barotrauma
}
#endif
MemoryStream imgStream = new MemoryStream();
CreateImage(defaultPreviewImageSize.X, defaultPreviewImageSize.Y, imgStream);
Submarine.SaveCurrent(savePath, imgStream);
using (MemoryStream imgStream = new MemoryStream())
{
CreateImage(defaultPreviewImageSize.X, defaultPreviewImageSize.Y, imgStream);
Submarine.SaveCurrent(savePath, imgStream);
}
Submarine.MainSub.CheckForErrors();
GUI.AddMessage(TextManager.Get("SubSavedNotification").Replace("[filepath]", Submarine.MainSub.FilePath), Color.Green);