System.AccessViolation Exception when rendering Pa - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
13 Jul 2017
Microsoft has ended support for Windows Phone 8.1
Read More...
Questions about Windows 8.1, 10, WindowsPhone, Windows UWP
  • Page:
  • 1

TOPIC: System.AccessViolation Exception when rendering Pa

System.AccessViolation Exception when rendering Pa 1 year 3 weeks ago #13029

  • Bouzidi
  • Bouzidi's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 13
  • Thank you received: 0
Hi,


I m trying to use Radaee Windows Lib to generate Bitmaps from a PDF file but I m facing a System.AccessViolation Exception "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." at the rendering RenderToBmp method :

page.RenderToBmp(m_dib, mat, true, PDF_RENDER_MODE.mode_normal);


In fact, I think that the problem is that the PDFMatrix cannot support a scale = 2.5 with a PageHeight 1350 and PageWidth 2400 because when I tried to change the scale to 2 the Exception disappears but I m getting a Bad rendering quality.


I m using this code to generate Bitmap from a Pdf File :

public async static Task RenderPDFPagesAsync(StorageFile file)
{
var tempFolder = await LocalFileManager.GetTempCachePdfFolderAsync(file);

var doc = new RDPDFLib.pdf.PDFDoc();
try
{
using (var stream = await file.OpenReadAsync())
{
doc.Open(stream, "");
}

double previousPageHeight = 0, previousPageWidth = 0;
PDFBmp m_dib = null;

foreach (var index in Enumerable.Range(0, (int)doc.PageCount))
{
var page = doc.GetPage(index);
try
{
var cFileName = index.ToString() + ".jpg";

page.RenderPrepare();

var pageHeight = doc.GetPageHeight(index);
var pageWidth = doc.GetPageWidth(index);
float scale = (float)1.0;
if (pageHeight < 1500 && pageWidth < 10000 || pageWidth < 1500 && pageHeight < 10000)
{
scale = (float)2.5;
}
pageHeight = pageHeight * scale;
pageWidth = pageWidth * scale;


if (previousPageHeight != pageHeight || previousPageWidth != pageWidth || m_dib == null)
{
m_dib = new PDFBmp((int)pageWidth, (int)pageHeight);
previousPageHeight = pageHeight;
previousPageWidth = pageWidth;
}

m_dib.Reset(0xFFFFFF);
PDFMatrix mat = new PDFMatrix(scale, -scale, 0, pageHeight);
page.RenderToBmp(m_dib, mat, true, PDF_RENDER_MODE.mode_normal);
m_dib.SaveJPG(tempFolder.Path + "\\" + cFileName, 90);
}
catch (Exception e) { } //TODO log
finally
{
page.Close();
}
}
}
catch (Exception) { }//TODO log
finally
{
doc.Close();
}
}

And This is the Exception StackTrace :

at RDPDFLib.pdf.PDFPage.RenderToBmp(PDFBmp bmp, PDFMatrix mat, Boolean show_annot, PDF_RENDER_MODE mode)
at SalesApp.Core.Common.PDFHelper.<RenderPDFPagesAsync>d__2.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(Object stateMachine)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c__DisplayClass4_0.<OutputAsyncCausalityEvents>b__0()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
at System.Runtime.CompilerServices.TaskAwaiter.<>c__DisplayClass11_0.<OutputWaitEtwEvents>b__0()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
at System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(Object state)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask)
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run(Task task, Boolean canInlineContinuationTask)
at System.Threading.Tasks.Task.FinishContinuations()
at System.Threading.Tasks.Task.FinishStageThree()
at System.Threading.Tasks.Task`1.TrySetResult(TResult result)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetResult(TResult result)
at SalesApp.Core.IO.LocalFileManager.<GetTempCachePdfFolderAsync>d__58.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(Object stateMachine)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c__DisplayClass4_0.<OutputAsyncCausalityEvents>b__0()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
at System.Runtime.CompilerServices.TaskAwaiter.<>c__DisplayClass11_0.<OutputWaitEtwEvents>b__0()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.<>c.<.cctor>b__8_0(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeInContext(Object thisObj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.WinRTSynchronizationContext.Invoker.Invoke()

Is there any way to solve this problem ?

Waiting for your response.

Best Regards,

BOUZIDI Hamza

Please Log in or Create an account to join the conversation.

Last edit: by Bouzidi.

System.AccessViolation Exception when rendering Pa 1 year 3 weeks ago #13030

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
Most probably is a memory issue related to the document + test environment.

So can you please send us the pdf and tell us the test device memory information (RAM)?

Please Log in or Create an account to join the conversation.

System.AccessViolation Exception when rendering Pa 1 year 3 weeks ago #13031

  • Bouzidi
  • Bouzidi's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 13
  • Thank you received: 0
Hi,

I m using a Surface Pro 4 with a 4Go RAM and this I joined pdf document I m using on the support Ticket Reference YLKM20171001-002533-SUP
because it is a client document with a confidentiality restrictions.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum