Skip to content

Commit

Permalink
Add workaround for texture freeing bug in SharpDX
Browse files Browse the repository at this point in the history
  • Loading branch information
Rampastring committed Jan 30, 2024
1 parent 0d16c05 commit c5c66cb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/TSMapEditor/Rendering/MGTMPImage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Rampastring.Tools;
using System;
using TSMapEditor.CCEngine;

namespace TSMapEditor.Rendering
Expand Down Expand Up @@ -48,8 +50,19 @@ public MGTMPImage(GraphicsDevice gd, TmpImage tmpImage, Palette palette, int til

public void Dispose()
{
if (Texture != null)
Texture.Dispose();
if (Texture == null && ExtraTexture == null)
return;

// Workaround for a bug in SharpDX where it can crash when freeing a texture
try
{
Texture?.Dispose();
ExtraTexture?.Dispose();
}
catch (InvalidOperationException)
{
Logger.Log($"Failed to free a TMP texture! TileSet: {TileSetId}");
}
}

private Texture2D TextureFromTmpImage(GraphicsDevice graphicsDevice, TmpImage image, Palette palette)
Expand Down

0 comments on commit c5c66cb

Please sign in to comment.