deprecate tryend and trybegin, add comments identifying potentially notable safeaction spots

This commit is contained in:
Dreitone committed 2025-12-05 23:50:34 -06:00
1 parent e8779556ee
commit 548d42e82b
3 files changed
+13 -12

No files matched your search

+2 -2
View File
@@ -890,7 +890,7 @@ namespace CalamityMod.ILEditing
private static void GeneralDrawLayer_DrawToLayer_BeforeAllTiles(On_Main.orig_DrawBackgroundBlackFill orig, Main self)
{
GeneralDrawLayer_DrawForSupportedSystems(GeneralDrawLayer.BeforeAllTiles);
// TODO: this is a bandaid solution, but almost assuredly the method call here does not always correct state
// TODO: [SAFEACTION] this is a bandaid solution, but almost assuredly the method call here does not always correct state
Main.spriteBatch.TryBegin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
orig(self);
}
@@ -931,7 +931,7 @@ namespace CalamityMod.ILEditing
{
orig(self);
GeneralDrawLayer_DrawForSupportedSystems(GeneralDrawLayer.AfterEverything);
// TODO: this is a bandaid solution, but almost assuredly the method call here does not always correct state
// TODO: [SAFEACTION] this is a bandaid solution, but almost assuredly the method call here does not always correct state
Main.spriteBatch.TryBegin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
}
#endregion
@@ -16,7 +16,7 @@ namespace CalamityMod.Systems
Main.QueueMainThreadAction(() =>
{
BakeBlendTexture_Inner(texture);
// TODO: Bandaid fix
// TODO: [SAFEACTION] Bandaid fix
Main.spriteBatch.TryEnd();
});
}
@@ -60,7 +60,7 @@ namespace CalamityMod.Systems
}
}
});
// TODO: bandaid fix
// TODO: [SAFEACTION] bandaid fix
Main.spriteBatch.TryEnd();
graphicsDevice.SetRenderTarget(null);
}
+9 -8
View File
@@ -49,14 +49,14 @@ namespace CalamityMod
{
if (spriteBatch is null)
return;
spriteBatch.TryEnd();
var rasterizer = settings.rasterizerState ?? Main.Rasterizer;
spriteBatch.TryBegin(sortMode, settings.blendState, settings.samplerState, settings.depthStencilState, rasterizer, effect, transformMatrix);
batchCallback?.Invoke();
spriteBatch.TryEnd();
var rasterizer = settings.rasterizerState ?? Main.Rasterizer;
spriteBatch.TryBegin(sortMode, settings.blendState, settings.samplerState, settings.depthStencilState, rasterizer, effect, transformMatrix);
batchCallback?.Invoke();
}
[Obsolete("This is violative of spritebatch's control flow and will eventually be removed")]
public static bool TryBegin(this SpriteBatch spriteBatch, SpriteSortMode sortMode,
BlendState blendState,
SamplerState samplerState,
@@ -75,7 +75,8 @@ namespace CalamityMod
return true;
}
}
[Obsolete("This is violative of spritebatch's control flow and will eventually be removed")]
public static bool TryEnd(this SpriteBatch spriteBatch)
{
if (!spriteBatch.HasBeginBeenCalled())