diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index d2d24c8b..acd375f7 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -1691,22 +1691,26 @@ private async Task> GetScaledBits(CancellationToken cancellatio private async Task> GetScaledEmojis(CancellationToken cancellationToken) { - var emojiTask = await TwitchHelper.GetEmojis(renderOptions.TempFolder, renderOptions.EmojiVendor, cancellationToken); + var emojis = await TwitchHelper.GetEmojis(renderOptions.TempFolder, renderOptions.EmojiVendor, _progress, cancellationToken); //Assume emojis are 4x (they're 72x72) double emojiScale = 0.5 * renderOptions.ReferenceScale * renderOptions.EmojiScale; - List emojiKeys = new List(emojiTask.Keys); + + // We can't just enumerate the dictionary because of the version checks + string[] emojiKeys = emojis.Keys.ToArray(); foreach (var emojiKey in emojiKeys) { - SKImageInfo oldEmojiInfo = emojiTask[emojiKey].Info; + SKBitmap bitmap = emojis[emojiKey]; + SKImageInfo oldEmojiInfo = bitmap.Info; SKImageInfo imageInfo = new SKImageInfo((int)(oldEmojiInfo.Width * emojiScale), (int)(oldEmojiInfo.Height * emojiScale)); SKBitmap newBitmap = new SKBitmap(imageInfo); - emojiTask[emojiKey].ScalePixels(newBitmap, SKFilterQuality.High); - emojiTask[emojiKey].Dispose(); - emojiTask[emojiKey] = newBitmap; + bitmap.ScalePixels(newBitmap, SKFilterQuality.High); + bitmap.Dispose(); + newBitmap.SetImmutable(); + emojis[emojiKey] = newBitmap; } - return emojiTask; + return emojis; } private (int startTick, int totalTicks) GetVideoTicks() diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index 624ed115..34d29197 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -660,7 +660,7 @@ public static async Task> GetChatBadges(List comments, return returnList; } - public static async Task> GetEmojis(string cacheFolder, EmojiVendor emojiVendor, CancellationToken cancellationToken = default) + public static async Task> GetEmojis(string cacheFolder, EmojiVendor emojiVendor, IProgress progress, CancellationToken cancellationToken = default) { var returnCache = new Dictionary(); @@ -722,6 +722,13 @@ public static async Task> GetEmojis(string cacheFol { await using var fs = File.OpenRead(emojiPath); var emojiImage = SKBitmap.Decode(fs); + + if (emojiImage is null) + { + progress.Report(new ProgressReport(ReportType.Log, $"Failed to decode emoji {Path.GetFileName(emojiPath)}, skipping.")); + continue; + } + returnCache.Add(Path.GetFileNameWithoutExtension(emojiPath), emojiImage); }