Skip to content

Commit

Permalink
Fix sporadic 'A callback was made on a garbage collected delegate' bug
Browse files Browse the repository at this point in the history
Update NuGet package details
  • Loading branch information
rndusr0 committed Feb 7, 2019
1 parent 627bf27 commit a2f8e8e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/DinkToPdf/BasicConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public virtual byte[] Convert(IDocument document)
}

Tools.DestroyConverter(converter);
ProcessingDocument = null;

return result;
}
Expand Down
21 changes: 12 additions & 9 deletions src/DinkToPdf/DinkToPdf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<VersionPrefix>1.0.9</VersionPrefix>
<VersionSuffix>netcore2.1-wkhtmltopdf-v0.12.5</VersionSuffix>
<VersionSuffix>20190207.1+netstandard-2.0-netcore-2.1-wkhtmltopdf-0.12.5</VersionSuffix>
<TargetFramework>netstandard2.0</TargetFramework>
<NoWarn>$(NoWarn);1591</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -15,18 +15,21 @@

<!--NuGet -->
<PropertyGroup>
<PackageId>DinkToPdf_netstandard20</PackageId>
<PackageId>RndUsr0.DinkToPdf</PackageId>
<Description>
.NET Core P/Invoke wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
Upgraded to .NET Standard 2.0, .NET Core 2.1, Windows wkhtmltopdf v0.12.5
- Upgraded to .NET Standard 2.0, .NET Core 2.1, wkhtmltopdf v0.12.5
- Fix sporadic 'A callback was made on a garbage collected delegate' bug
</Description>
<Copyright>Copyright 2017</Copyright>
<Authors>Rok Dvojmoč, upgraded by Chris Bryden</Authors>
<License>MIT</License>
<Authors>Rok Dvojmoč, Chris Bryden</Authors>
<PackageProjectUrl>https://github.com/rdvojmoc/DinkToPdf</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/rdvojmoc/DinkToPdf/blob/master/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/rndusr0/DinkToPdf</RepositoryUrl>
<IncludeBuildOutput>true</IncludeBuildOutput>
<IncludeSymbols>true</IncludeSymbols>
<PackageTags>wkhtmltopdf;netstandard;html;pdf;wrapper</PackageTags>
<PackageTags>wkhtmltopdf;netstandard;netcore;html;pdf;wrapper</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

Expand All @@ -40,19 +43,19 @@
<PackagePath>runtimes\win-x64\native</PackagePath>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\v0.12.4\32 bit\libwkhtmltox.dylib">
<Content Include="..\..\v0.12.5\32 bit\libwkhtmltox.dylib">
<Pack>true</Pack>
<PackagePath>runtimes\osx-x86\native</PackagePath>
</Content>
<Content Include="..\..\v0.12.4\32 bit\libwkhtmltox.so">
<Content Include="..\..\v0.12.5\32 bit\libwkhtmltox.so">
<Pack>true</Pack>
<PackagePath>runtimes\linux-x86\native</PackagePath>
</Content>
<Content Include="..\..\v0.12.4\64 bit\libwkhtmltox.dylib">
<Content Include="..\..\v0.12.5\64 bit\libwkhtmltox.dylib">
<Pack>true</Pack>
<PackagePath>runtimes\osx-x64\native</PackagePath>
</Content>
<Content Include="..\..\v0.12.4\64 bit\libwkhtmltox.so">
<Content Include="..\..\v0.12.5\64 bit\libwkhtmltox.so">
<Pack>true</Pack>
<PackagePath>runtimes\linux-x64\native</PackagePath>
</Content>
Expand Down
17 changes: 13 additions & 4 deletions src/DinkToPdf/PdfTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ public sealed class PdfTools : ITools
{
public bool IsLoaded { get; private set; }

//used to maintain a reference to delegates to prevent them being garbage collected...
private List<object> _Delegates = new List<object>();

public PdfTools()
{
IsLoaded = false;
}

public void Load() {

public void Load()
{

if (IsLoaded)
{
Expand Down Expand Up @@ -55,7 +59,7 @@ public unsafe string GetGlobalSetting(IntPtr settings, string name)
//default const char * size is 2048 bytes
byte[] buffer = new byte[2048];

fixed (byte* tempBuffer = buffer )
fixed (byte* tempBuffer = buffer)
{
WkHtmlToXBindings.wkhtmltopdf_get_global_setting(settings, name, tempBuffer, buffer.Length);
}
Expand Down Expand Up @@ -118,7 +122,7 @@ public bool DoConversion(IntPtr converter)

public void DestroyConverter(IntPtr converter)
{
WkHtmlToXBindings.wkhtmltopdf_destroy_converter(converter);
WkHtmlToXBindings.wkhtmltopdf_destroy_converter(converter);
}

public byte[] GetConversionResult(IntPtr converter)
Expand All @@ -134,26 +138,31 @@ public byte[] GetConversionResult(IntPtr converter)

public int SetPhaseChangedCallback(IntPtr converter, VoidCallback callback)
{
_Delegates.Add(callback);
return WkHtmlToXBindings.wkhtmltopdf_set_phase_changed_callback(converter, callback);
}

public int SetProgressChangedCallback(IntPtr converter, VoidCallback callback)
{
_Delegates.Add(callback);
return WkHtmlToXBindings.wkhtmltopdf_set_progress_changed_callback(converter, callback);
}

public int SetFinishedCallback(IntPtr converter, IntCallback callback)
{
_Delegates.Add(callback);
return WkHtmlToXBindings.wkhtmltopdf_set_finished_callback(converter, callback);
}

public int SetWarningCallback(IntPtr converter, StringCallback callback)
{
_Delegates.Add(callback);
return WkHtmlToXBindings.wkhtmltopdf_set_warning_callback(converter, callback);
}

public int SetErrorCallback(IntPtr converter, StringCallback callback)
{
_Delegates.Add(callback);
return WkHtmlToXBindings.wkhtmltopdf_set_error_callback(converter, callback);
}

Expand Down

0 comments on commit a2f8e8e

Please sign in to comment.