From 8922030727304f085cabcda1cd19c69ab30fcbdf Mon Sep 17 00:00:00 2001 From: Aragas Date: Thu, 6 Oct 2016 18:18:10 +0300 Subject: [PATCH] Not even ashamed of my dirty fixes --- 2.5DHero/2.5DHero/Screens/BattleIntroScreen.vb | 12 ++++++++++++ 2.5DHero/2.5DHero/Screens/GUI/InputScreen.vb | 11 +++++++++++ 2.5DHero/2.5DHero/Screens/MapScreen.vb | 4 +++- 2.5DHero/2.5DHero/Screens/NewGameScreen.vb | 8 +++++++- 2.5DHero/2.5DHero/Screens/TradeScreen.vb | 8 ++++++-- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/2.5DHero/2.5DHero/Screens/BattleIntroScreen.vb b/2.5DHero/2.5DHero/Screens/BattleIntroScreen.vb index fef6ca1b7..64007e25c 100644 --- a/2.5DHero/2.5DHero/Screens/BattleIntroScreen.vb +++ b/2.5DHero/2.5DHero/Screens/BattleIntroScreen.vb @@ -180,6 +180,7 @@ Dim t1 As Texture2D = TextureManager.GetTexture("GUI\Intro\VSIntro", New Rectangle(CInt(barPosition.X), CInt(barPosition.Y), 128, 64), "") Dim t2 As Texture2D = TextureManager.GetTexture("GUI\Intro\" & Trainer.VSImageOrigin, New Rectangle(CInt(VSPosition.X), CInt(VSPosition.Y), Trainer.VSImageSize.Width, Trainer.VSImageSize.Height), "") Dim t3 As Texture2D = TextureManager.GetTexture("NPC\" & Trainer.SpriteName, New Rectangle(0, 64, 32, 32)) + Dim t3Disp = false Dim t4 As Texture2D = Nothing If Trainer.DoubleTrainer = True Then t4 = TextureManager.GetTexture("NPC\" & Trainer.SpriteName2, New Rectangle(0, 64, 32, 32)) @@ -192,6 +193,7 @@ Dim spriteSize As New Vector2(t.Width / 3.0F, t.Height / 4.0F) 'It will leak t3 = TextureManager.TextureRectangle(t, New Rectangle(0, CInt(spriteSize.Y * 2), CInt(spriteSize.X), CInt(spriteSize.Y))) + t3Disp = true End If End If End If @@ -220,6 +222,10 @@ Core.SpriteBatch.Draw(t3, New Rectangle(Core.windowSize.Width - 310, CInt(Core.windowSize.Height / 2 - 230), 256, 256), Color.White) End If Core.SpriteBatch.Draw(t2, New Rectangle(420 - CInt(CInt(1.29 * value) / 3), CInt(Core.windowSize.Height / 2 - 20) - CInt(CInt(1 * value) / 3), CInt(1.12 * CInt(value / 1.5F)), 1 * CInt(value / 1.5F)), Color.White) + + If t3Disp Then + t3.Dispose() + End If End Sub Private Function ReplaceIntroName(ByVal Name As String) As String @@ -243,6 +249,7 @@ Dim t1 As Texture2D = TextureManager.GetTexture("GUI\Intro\VSIntro", New Rectangle(CInt(barPosition.X), CInt(barPosition.Y), 128, 64), "") Dim t2 As Texture2D = TextureManager.GetTexture("GUI\Intro\VSIntro", New Rectangle(CInt(VSPosition.X), CInt(VSPosition.Y), 61, 54), "") Dim t3 As Texture2D = TextureManager.GetTexture("NPC\" & Trainer.SpriteName, New Rectangle(0, 64, 32, 32)) + Dim t3Disp = false Dim t4 As Texture2D = Nothing If Trainer.DoubleTrainer = True Then t4 = TextureManager.GetTexture("NPC\" & Trainer.SpriteName2, New Rectangle(0, 64, 32, 32)) @@ -255,6 +262,7 @@ Dim spriteSize As New Vector2(t.Width / 3.0F, t.Height / 4.0F) 'It will leak t3 = TextureManager.TextureRectangle(t, New Rectangle(0, CInt(spriteSize.Y * 2), CInt(spriteSize.X), CInt(spriteSize.Y))) + t3Disp = true End If End If End If @@ -281,6 +289,10 @@ Core.SpriteBatch.DrawString(FontManager.InGameFont, Trainer.Name, New Vector2((Core.windowSize.Width - (textPosition - 300)).Clamp(CInt(Core.windowSize.Width / 2 - tWidth / 2), Core.windowSize.Width), Core.windowSize.Height - 180), Color.White, 0.0F, New Vector2(0), 3.0F, SpriteEffects.None, 0.0F) End If End If + + If t3Disp Then + t3.Dispose() + End If End Sub Public Overrides Sub Update() diff --git a/2.5DHero/2.5DHero/Screens/GUI/InputScreen.vb b/2.5DHero/2.5DHero/Screens/GUI/InputScreen.vb index 544e54e19..9e5a527ee 100644 --- a/2.5DHero/2.5DHero/Screens/GUI/InputScreen.vb +++ b/2.5DHero/2.5DHero/Screens/GUI/InputScreen.vb @@ -424,4 +424,15 @@ End Class + + Protected Overrides Sub Finalize() + If Sprites IsNot Nothing And Sprites.Count > 1 + For Each sprite in Sprites + If sprite IsNot Nothing + sprite.Dispose() + End If + Next + End If + End Sub + End Class \ No newline at end of file diff --git a/2.5DHero/2.5DHero/Screens/MapScreen.vb b/2.5DHero/2.5DHero/Screens/MapScreen.vb index 1885dbb55..03b54a2a3 100644 --- a/2.5DHero/2.5DHero/Screens/MapScreen.vb +++ b/2.5DHero/2.5DHero/Screens/MapScreen.vb @@ -475,7 +475,9 @@ If drawObjects(3) = True Then For Each Pokes As Roaming In RoamingPoke - Core.SpriteBatch.Draw(Pokes.getTexture(), Pokes.getRectangle(mapOffset), Color.White) + Dim text = Pokes.getTexture() + Core.SpriteBatch.Draw(text, Pokes.getRectangle(mapOffset), Color.White) + text.Dispose() Next End If diff --git a/2.5DHero/2.5DHero/Screens/NewGameScreen.vb b/2.5DHero/2.5DHero/Screens/NewGameScreen.vb index d79e318fa..5380a00e1 100644 --- a/2.5DHero/2.5DHero/Screens/NewGameScreen.vb +++ b/2.5DHero/2.5DHero/Screens/NewGameScreen.vb @@ -368,7 +368,10 @@ If ControllerHandler.ButtonPressed(Buttons.X) = True Then 'It will leak - Core.SetScreen(New InputScreen(Core.CurrentScreen, "Player", InputScreen.InputModes.Name, Me.CurrentText, 14, {TextureManager.TextureRectangle(TextureManager.GetTexture("Textures\NPC\" & startSkins(SkinIndex)), New Rectangle(0, 64, 32, 32))}.ToList(), AddressOf Me.ConfirmInput)) + Core.SetScreen(New InputScreen(Core.CurrentScreen, "Player", InputScreen.InputModes.Name, Me.CurrentText, 14, + { + TextureManager.TextureRectangle(TextureManager.GetTexture("Textures\NPC\" & startSkins(SkinIndex)),New Rectangle(0, 64, 32, 32)) + }.ToList(), AddressOf Me.ConfirmInput)) Else KeyBindings.GetNameInput(Me.CurrentText, 14) @@ -561,5 +564,8 @@ If texture2 IsNot Nothing texture2.Dispose() End If + If skinTexture IsNot Nothing + skinTexture.Dispose() + End If End Sub End Class \ No newline at end of file diff --git a/2.5DHero/2.5DHero/Screens/TradeScreen.vb b/2.5DHero/2.5DHero/Screens/TradeScreen.vb index e1c15b37a..720563c7c 100644 --- a/2.5DHero/2.5DHero/Screens/TradeScreen.vb +++ b/2.5DHero/2.5DHero/Screens/TradeScreen.vb @@ -439,7 +439,9 @@ Public Class TradeScreen If i <= Me.loadedBuyCategories.Count - 1 Then Dim p As Integer = i - Scroll - DrawButton(New Vector2(100, 100 + p * 96), 5, Me.loadedBuyCategories(i).ToString(), 16, GetItemTypeTexture(Me.loadedBuyCategories(i))) + Dim texture As Texture2D = GetItemTypeTexture(Me.loadedBuyCategories(i)) + DrawButton(New Vector2(100, 100 + p * 96), 5, Me.loadedBuyCategories(i).ToString(), 16, texture) + texture.Dispose() End If Next @@ -849,7 +851,9 @@ Public Class TradeScreen If i <= Me.loadedSellCategories.Count - 1 Then Dim p As Integer = i - Scroll - DrawButton(New Vector2(100, 100 + p * 96), 5, Me.loadedSellCategories(i).ToString(), 16, GetItemTypeTexture(Me.loadedSellCategories(i))) + Dim texture As Texture2D = GetItemTypeTexture(Me.loadedSellCategories(i)) + DrawButton(New Vector2(100, 100 + p * 96), 5, Me.loadedSellCategories(i).ToString(), 16, texture) + texture.Dispose() End If Next