summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ContentHelper.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-04-29 21:45:37 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-04-29 21:45:37 -0400
commitff5d1ef4e4a096405b343de3f6d27715c248de3b (patch)
tree29ec4c82f4c07f54513ec626254f8952c98ed123 /src/StardewModdingAPI/Framework/ContentHelper.cs
parent014014ca0f50f44d8767e46eb82625b2120282e0 (diff)
downloadSMAPI-ff5d1ef4e4a096405b343de3f6d27715c248de3b.tar.gz
SMAPI-ff5d1ef4e4a096405b343de3f6d27715c248de3b.tar.bz2
SMAPI-ff5d1ef4e4a096405b343de3f6d27715c248de3b.zip
add internal context for more robust draw loop detection (#257)
Diffstat (limited to 'src/StardewModdingAPI/Framework/ContentHelper.cs')
-rw-r--r--src/StardewModdingAPI/Framework/ContentHelper.cs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Framework/ContentHelper.cs b/src/StardewModdingAPI/Framework/ContentHelper.cs
index 9abfc7e9..04317a84 100644
--- a/src/StardewModdingAPI/Framework/ContentHelper.cs
+++ b/src/StardewModdingAPI/Framework/ContentHelper.cs
@@ -141,9 +141,11 @@ namespace StardewModdingAPI.Framework
/// <remarks>Based on <a href="https://gist.github.com/Layoric/6255384">code by Layoric</a>.</remarks>
private Texture2D PremultiplyTransparency(Texture2D texture)
{
- if (Game1.graphics.GraphicsDevice.GetRenderTargets().Any()) // TODO: use a more robust check to detect if the game is drawing
+ // validate
+ if (Context.IsInDrawLoop)
throw new NotSupportedException("Can't load a PNG file while the game is drawing to the screen. Make sure you load content outside the draw loop.");
+ // process texture
using (RenderTarget2D renderTarget = new RenderTarget2D(Game1.graphics.GraphicsDevice, texture.Width, texture.Height))
using (SpriteBatch spriteBatch = new SpriteBatch(Game1.graphics.GraphicsDevice))
{