Skip to content

Commit

Permalink
Fix invalid memory access (idk how this fixes it)
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Aug 21, 2020
1 parent b986854 commit 6cb9b2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
26 changes: 17 additions & 9 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -395,15 +396,7 @@ private void RenderVideo(ChatRenderOptions renderOptions, Queue<TwitchComment> f
ffmpegStream.Write(bytes);
if (renderOptions.GenerateMask)
{
SKBitmap maskBitmap = new SKBitmap(renderOptions.ChatWidth, renderOptions.ChatHeight);
using (SKCanvas maskCanvas = new SKCanvas(maskBitmap))
{
maskCanvas.Clear(SKColors.White);
maskCanvas.DrawBitmap(bufferBitmap, 0, 0, new SKPaint() { BlendMode = SKBlendMode.DstIn });
}
var pixMask = maskBitmap.PeekPixels();
var dataMask = SKData.Create(pixMask.GetPixels(), pixMask.Info.BytesSize);
var bytesMask = dataMask.ToArray();
byte[] bytesMask = GetMaskBytes(bufferBitmap, renderOptions);
maskStream.Write(bytesMask);
}

Expand Down Expand Up @@ -433,6 +426,21 @@ private void RenderVideo(ChatRenderOptions renderOptions, Queue<TwitchComment> f
progress.Report(new ProgressReport() { reportType = ReportType.Log, data = $"FINISHED. RENDER TIME: {(int)stopwatch.Elapsed.TotalSeconds}s SPEED: {(duration / stopwatch.Elapsed.TotalSeconds).ToString("0.##")}x" });
process.WaitForExit();
}

private byte[] GetMaskBytes(SKBitmap bufferBitmap, ChatRenderOptions renderOptions)
{
SKBitmap maskBitmap = new SKBitmap(renderOptions.ChatWidth, renderOptions.ChatHeight);
using (SKCanvas maskCanvas = new SKCanvas(maskBitmap))
{
maskCanvas.Clear(SKColors.White);
maskCanvas.DrawBitmap(bufferBitmap, 0, 0, new SKPaint() { BlendMode = SKBlendMode.DstIn });
}
var pixMask = maskBitmap.PeekPixels();
var dataMask = SKData.Create(pixMask.GetPixels(), pixMask.Info.BytesSize);
var bytesMask = dataMask.ToArray();
return bytesMask;
}

public static SKBitmap DrawTimestamp(SKBitmap sectionImage, List<SKBitmap> imageList, SKPaint messageFont, ChatRenderOptions renderOptions, Comment comment, Size canvasSize, ref Point drawPos, ref int default_x)
{
SKCanvas sectionImageCanvas = new SKCanvas(sectionImage);
Expand Down
5 changes: 1 addition & 4 deletions TwitchDownloaderWPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ namespace TwitchDownloaderWPF
/// </summary>
public partial class App : Application
{
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
File.AppendAllText("errors.txt", e.Exception.ToString());
}

}
}

0 comments on commit 6cb9b2b

Please sign in to comment.