From 44c9679bd7b4d36362dd1bbedaeddb349040d394 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Wed, 30 Aug 2023 16:15:27 +0200 Subject: [PATCH] Update Animation.cs to avoid cross thread access --- PCK-Studio/Internal/Animation.cs | 35 +++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/PCK-Studio/Internal/Animation.cs b/PCK-Studio/Internal/Animation.cs index 163ce6b7..21f6793e 100644 --- a/PCK-Studio/Internal/Animation.cs +++ b/PCK-Studio/Internal/Animation.cs @@ -74,7 +74,23 @@ namespace PckStudio.Internal public class Frame { public readonly Image Texture; - public int Ticks; + public int Ticks + { + get + { + return _ticks; + } + set + { + lock(l_ticks) + { + _ticks = value; + } + } + } + + private int _ticks; + private object l_ticks = new object(); public Frame(Image texture) : this(texture, MinimumFrameTime) { } @@ -169,7 +185,10 @@ namespace PckStudio.Internal public void SetFrame(int frameIndex, Frame frame) { - frames[frameIndex] = frame; + lock(frames) + { + frames[frameIndex] = frame; + } } public void SetFrame(int frameIndex, int textureIndex, int frameTime = MinimumFrameTime) @@ -196,15 +215,21 @@ namespace PckStudio.Internal internal void SetFrameTicks(int ticks) { - foreach (var frame in frames) + lock(frames) { - frame.Ticks = ticks; + foreach (var frame in frames) + { + frame.Ticks = ticks; + } } } internal void SwapFrames(int sourceIndex, int destinationIndex) { - frames.Swap(sourceIndex, destinationIndex); + lock(frames) + { + frames.Swap(sourceIndex, destinationIndex); + } } } }