Permalink
Browse files

Fix game crashing with stack overflow when using 512x512 (or higher) …

…animation frames. (Thanks Bot)
  • Loading branch information...
UnknownShadow200 committed Jan 11, 2018
1 parent 8c25212 commit 5c4d42b49062bbaf1653fe271b3d466804989948
Showing with 14 additions and 2 deletions.
  1. +14 −2 ClassicalSharp/TexturePack/Animations.cs
@@ -144,10 +144,22 @@ public class Animations : IGameComponent {
}
unsafe void DrawAnimation(AnimationData data, int texId, int size) {
if (size <= 128) {
byte* temp = stackalloc byte[size * size * 4];
DrawAnimationCore(data, texId, size, temp);
} else {
// cannot allocate memory on the stack for very big animation.png frames
byte[] temp = new byte[size * size * 4];
fixed (byte* ptr = temp) {
DrawAnimationCore(data, texId, size, ptr);
}
}
}
unsafe void DrawAnimationCore(AnimationData data, int texId, int size, byte* temp) {
TerrainAtlas1D atlas = game.TerrainAtlas1D;
int index = atlas.Get1DIndex(texId);
int rowNum = atlas.Get1DRowId(texId);
byte* temp = stackalloc byte[size * size * 4];
int rowNum = atlas.Get1DRowId(texId);
animPart.SetData(size, size, size * 4, (IntPtr)temp, false);
if (data == null) {

0 comments on commit 5c4d42b

Please sign in to comment.