AdaskoTheBeAsT / WkHtmlToX

C# wrapper for wkhtmltopdf.org Html to Pdf library
MIT License
4 stars 4 forks source link

Crashes trying to convert an image #7

Open pf56 opened 1 year ago

pf56 commented 1 year ago

I'm trying to use the ImageConverter to convert a website to an image, but the application crashes. This might be an issue with libwkhtmltox itself, but I figured I'd raise the issue with you first.

Running on Windows 11, using .NET 6, WkHtmlToX v6.0.0 and WkHtmlToX.native.win.x64 v0.12.6.

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at AdaskoTheBeAsT.WkHtmlToX.Native.ImageNativeMethods.wkhtmltoimage_destroy_converter(IntPtr)
--------------------------------
   at AdaskoTheBeAsT.WkHtmlToX.Modules.WkHtmlToImageModule.DestroyConverter(IntPtr)
   at AdaskoTheBeAsT.WkHtmlToX.Engine.ImageProcessor.Convert(AdaskoTheBeAsT.WkHtmlToX.Abstractions.IHtmlToImageDocument, System.Func`2<Int32,System.IO.Stream>)
   at AdaskoTheBeAsT.WkHtmlToX.Engine.WkHtmlToXEngine.AdaskoTheBeAsT.WkHtmlToX.WorkItems.IWorkItemVisitor.Visit(AdaskoTheBeAsT.WkHtmlToX.WorkItems.ImageConvertWorkItem)
   at AdaskoTheBeAsT.WkHtmlToX.WorkItems.ImageConvertWorkItem.Accept(AdaskoTheBeAsT.WkHtmlToX.WorkItems.IWorkItemVisitor)
   at AdaskoTheBeAsT.WkHtmlToX.Engine.WkHtmlToXEngine.Process(System.Object)
   at System.Threading.Thread.StartCallback()
using AdaskoTheBeAsT.WkHtmlToX;
using AdaskoTheBeAsT.WkHtmlToX.Documents;
using AdaskoTheBeAsT.WkHtmlToX.Engine;
using Microsoft.IO;

RecyclableMemoryStreamManager streamManager = new();
var configuration = new WkHtmlToXConfiguration((int)Environment.OSVersion.Platform, null);

using var engine = new WkHtmlToXEngine(configuration);
engine.Initialize();

HtmlToImageDocument doc = new()
{
    ImageSettings =
    {
        In = "https://www.google.com/",
        Format = "jpg",
        Out = ""
    }
};

ImageConverter converter = new(engine);
Stream? stream;

Console.WriteLine("before convert");

var converted = await converter.ConvertAsync(
    doc,
    length =>
    {
        stream = streamManager.GetStream(
            Guid.NewGuid(),
            "wkhtmltox",
            length);

        return stream;
    },
    CancellationToken.None);

Console.WriteLine("converted: " + converted);
AdaskoTheBeAsT commented 1 year ago

I will check and get back to you

AdaskoTheBeAsT commented 1 year ago

Indeed there is something wrong in native lib - I will need to remove this functionality

91651 commented 8 months ago

Indeed there is something wrong in native lib - I will need to remove this functionality

expect updates

91651 commented 8 months ago

I submitted a PR to fix the issue above.

AdaskoTheBeAsT commented 8 months ago

@91651 thanks a lot - soon it will be released