Skip to content

Commit

Permalink
Add success check to TwitchEmote image decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Jul 7, 2023
1 parent 90cbb34 commit 783d5c3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions TwitchDownloaderCore/TwitchObjects/TwitchEmote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace TwitchDownloaderCore.TwitchObjects
{

public enum EmoteProvider
{
FirstParty,
Expand Down Expand Up @@ -35,7 +34,10 @@ public sealed class TwitchEmote : IDisposable
public TwitchEmote(byte[] imageData, EmoteProvider emoteProvider, int imageScale, string imageId, string imageName)
{
using MemoryStream ms = new MemoryStream(imageData);
Codec = SKCodec.Create(ms);
Codec = SKCodec.Create(ms, out var result);
if (Codec is null)
throw new BadImageFormatException($"Skia was unable to decode {imageName} ({imageId}). Returned: {result}");

EmoteProvider = emoteProvider;
Id = imageId;
Name = imageName;
Expand All @@ -54,10 +56,10 @@ private void CalculateDurations()
if (FrameCount == 1)
return;

var frameInfo = Codec.FrameInfo;
var frameInfos = Codec.FrameInfo;
for (int i = 0; i < FrameCount; i++)
{
var duration = frameInfo[i].Duration / 10;
var duration = frameInfos[i].Duration / 10;
EmoteFrameDurations.Add(duration);
TotalDuration += duration;
}
Expand Down

0 comments on commit 783d5c3

Please sign in to comment.