Skip to content

Commit 1e18ae8

Browse files
Fix rapid allocation of RenderTarget2D in Sprite.Image setter
1 parent 616d2bb commit 1e18ae8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Wobble/Graphics/Sprites/Sprite.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ public Texture2D Image
3838

3939
Origin = new Vector2(Image.Width * Pivot.X, Image.Height * Pivot.Y);
4040

41-
_intermediateImage = new RenderTarget2D(GameBase.Game.GraphicsDevice, _image.Width, _image.Height, false,
42-
GameBase.Game.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None);
43-
44-
if (AdditionalPasses != null && AdditionalPasses.Count > 0)
41+
if (AdditionalPasses != null && AdditionalPasses.Count > 0)
42+
{
43+
_intermediateImage?.Dispose();
44+
_intermediateImage = new RenderTarget2D(GameBase.Game.GraphicsDevice, _image.Width, _image.Height, false,
45+
GameBase.Game.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None);
4546
GameBase.Game.ScheduledRenderTargetDraws.Add(PerformAdditionalPasses);
47+
}
4648

4749
RecalculateRectangles();
4850
}

0 commit comments

Comments
 (0)