Print Page | Close Window

EOutOfMemory DrawLine/DrawPath

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3990
Printed Date: 16 Apr 24 at 12:35PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: EOutOfMemory DrawLine/DrawPath
Posted By: fellafoo
Subject: EOutOfMemory DrawLine/DrawPath
Date Posted: 25 Jul 22 at 8:29PM
Hello,

I'm hoping someone can help me with an out of memory error I'm getting while making repeated calls (around 13,000) to DrawLine and StartPath, AddLineToPath, DrawPath.

The debugger breaks at...
procedure TPDFPageTree.PainterChange(Sender: TObject);
begin
  if (FLayer > 0) and (FLayer <= Length(FPageContent)) then
    FPageContent[FLayer - 1].SetTo(FPainter.Source, False);
end;
...in DebenuPDFLibraryPageTree.pas.

I noticed the crash occurs when DrawLine X1 = X2 and Y1 = Y2. I put a test prior to the call for example:
if (X1 <> X2) and (Y2 <> Y2) then
  PDFLib.DrawLine(X1, Y1, X2, Y2);
The crash no longer occurs, but a lot of vectors are missing from the output. Do I need to do this test, and if so, should I use a 'near-identical' test?

Thank You,

MFM



Replies:
Posted By: fellafoo
Date Posted: 25 Jul 22 at 9:28PM
Well,

I take back my statement about matching points. In my latest test, about 1800 lines with matching endpoints are drawn before the crash occurs. So, I'm not sure where to look next.

MFM


Posted By: tfrost
Date Posted: 26 Jul 22 at 10:08AM
Is is a genuine out-of-memory condition?  Have you checked for a leak using the full version of FastMM? If you suspect you are really out of memory, and you are using 32-bit, does the same happen when you use 64-bit?


Posted By: fellafoo
Date Posted: 26 Jul 22 at 1:36PM
I'm not convinced it's an out-of-memory condition. With this particular test file, the error occurs around 10,000 paths/lines. I can create PDFs containing 30 - 40K paths/lines from other sources without error.

So, I'm trying to narrow down which set of vectors is causing the crash. I haven's used FastMM and building a 64bit test is not an option for me.


Posted By: fellafoo
Date Posted: 26 Jul 22 at 2:57PM
Update:

Perhaps it has something to do with memory. I've been able to create A, B, and C size sheets using the same data. However, each time I try D (24"x36") the crash occurs.


Posted By: fellafoo
Date Posted: 26 Jul 22 at 3:18PM
When I drop the Dpi to 300, I'm able to output a 24x36 sheet. However, I'm surprised because I'm only writing vector data. Why would the Dpi make a difference in this case?

And why don't other documents fail at 600 dpi with more vectors?

Confused


Posted By: fellafoo
Date Posted: 26 Jul 22 at 4:03PM
Unfortunately, dropping the Dpi to 300 doesn't always work. Here's the 'typical' call stack for what it's worth...
TPDFPageTree.PainterChange(???)
TPDFPainter.RunOnChanged
TPDFPainter.DrawLine(469.2,661.92,469.44,661.92)
TQuickPDF.DrawLine(6.5166666667,23.916666667,6.52,23.916666667)


Posted By: tfrost
Date Posted: 26 Jul 22 at 10:19PM
I don't think you have much chance of finding the actual problem by trying different parameters which do and do not cause a crash, although you may be able to identify the limits. Since I never use QPDF to draw lines and paths, I do not have a feel for whether 13000 is a big number or not. But I do debug Delphi applications and exceptions.

I would start from the exception message, which may not show the same address as the break in the debugger if the debugger cannot see the source at the exception address. If you have an exception you must have the address at which it occurs. If this is an address in your main program, and you have a link map, then you can find which module that is. If it is not in your main program, use Process Explorer to show DLL load addresses (before the crash occurs) and you will know which DLL it is in, and if you have a link map for the DLL, which module. If the exception address is not in your process at all, then you are out of luck, but at least you know more: that it is most likely a bug causing a stack overwrite or wild branch. If the exception is in the memory manager, then it is worth investing in the time to get the version of Fastmm which provides easy-to-use monitoring and debugging features. But if it is not in the memory manager, the knowledge acquired by all this may lead you to a module for which the 'QPDF source' (which it sounds as if you have) does not include the source.  I wish you luck!



Posted By: fellafoo
Date Posted: 28 Jul 22 at 4:54PM
This is looking like 'bloat' I am unintentionally creating when writing the vector data to the PDF document. So, I need to find where, perhaps, I'm writing duplicate data or something along those lines. Is there a way to look at the 'guts' of the file I'm creating to see what the duplicate data might be?


Posted By: fellafoo
Date Posted: 28 Jul 22 at 6:49PM
Here's the order of events when I create a simple file with two rectangles. One is made up of 4 lines and the other is a polyline.

PDF_NewPDFLib
PDF Renderer: PDFium
PDF_CompressImages: 1
SetGlobalMeasurementUnits: 2
PDF_SetPageDimensions - Width: 5100 Height: 6600
PDF_SetGlobalOrigin: 5
PDF_SetPageBox - Left: 0 Top: 0 Width: 8.5 Height: 11
PDF_SetLineColor: 0 0 0
SetLineWidth: 0.00984251968503937
PDF_SetLineCap: 1
PDF_SetLineJoin: 1
PDF_SetLineDashEx: 
PDF_SetPNGTransparencyColor: 255 255 255
PDF_OptionalContentGroupCount: 0
PDF_ContentStreamCount: 1
PDF_NewOptionalContentGroup: Layer001 = 1476395009
PDF_SelectContentStream: 1
SetLineWidth: 0.00166666666666667
PDF_SetLineDashEx: 
PDF_SetLineColor: 0 0 0
PDF_DrawLine - x1: 1230 y1: 480 y2: 1230 y2: 2880
PDF_OptionalContentGroupCount: 1
PDF_ContentStreamCount: 1
PDF_SetContentStreamOptional: 1476395009
PDF_SetOptionalContentGroupVisible: 1476395009 = 1
PDF_OptionalContentGroupCount: 1
PDF_ContentStreamCount: 1
PDF_GetOptionalContentGroupID: 1 = 1476395009
PDF_GetOptionalContentGroupName: 1476395009 = Layer001
PDF_SelectContentStream: 1
SetLineWidth: 0.00166666666666667
PDF_DrawLine - x1: 1230 y1: 2880 y2: 3630 y2: 2880
PDF_OptionalContentGroupCount: 1
PDF_ContentStreamCount: 1
PDF_SetContentStreamOptional: 1476395009
PDF_SetOptionalContentGroupVisible: 1476395009 = 1
PDF_OptionalContentGroupCount: 1
PDF_ContentStreamCount: 1
PDF_GetOptionalContentGroupID: 1 = 1476395009
PDF_GetOptionalContentGroupName: 1476395009 = Layer001
PDF_SelectContentStream: 1
SetLineWidth: 0.00166666666666667
PDF_DrawLine - x1: 3630 y1: 2880 y2: 3630 y2: 480
PDF_OptionalContentGroupCount: 1
PDF_ContentStreamCount: 1
PDF_SetContentStreamOptional: 1476395009
PDF_SetOptionalContentGroupVisible: 1476395009 = 1
PDF_OptionalContentGroupCount: 1
PDF_ContentStreamCount: 1
PDF_GetOptionalContentGroupID: 1 = 1476395009
PDF_GetOptionalContentGroupName: 1476395009 = Layer001
PDF_SelectContentStream: 1
SetLineWidth: 0.00166666666666667
PDF_DrawLine - x1: 3630 y1: 480 y2: 1230 y2: 480
PDF_OptionalContentGroupCount: 1
PDF_ContentStreamCount: 1
PDF_SetContentStreamOptional: 1476395009
PDF_SetOptionalContentGroupVisible: 1476395009 = 1
PDF_OptionalContentGroupCount: 1
PDF_ContentStreamCount: 1
PDF_GetOptionalContentGroupID: 1 = 1476395009
PDF_GetOptionalContentGroupName: 1476395009 = Layer001
PDF_SelectContentStream: 1
SetLineWidth: 0.00166666666666667
PDF_StartPath: 
PDF_AddLineToPath: 
PDF_AddLineToPath: 
PDF_AddLineToPath: 
PDF_AddLineToPath: 
PDF_DrawPath: 
PDF_OptionalContentGroupCount: 1
PDF_ContentStreamCount: 1
PDF_SetContentStreamOptional: 1476395009
PDF_SetOptionalContentGroupVisible: 1476395009 = 1
PDF_SaveToStream


Posted By: tfrost
Date Posted: 29 Jul 22 at 9:45AM
I seem to be the only user in the forum who has commented, and I have to drop out now, because as I said I am not familiar with using these specific functions in QPDF.  Maybe someone else here who knows more about these functions and their possible limitations can help you.


Posted By: Ingo
Date Posted: 29 Jul 22 at 10:12AM
I'm not able to help but i've searched through the forum here regarding similar issues.
Perhaps the links below let you go a step ahead...

Links regarding similar Probs perhaps with good hints:
http://www.quickpdf.org/forum/forum_posts.asp?TID=3254&KW=DrawLine&PID=12948&title=speed-up-running-time#12948
http://www.quickpdf.org/forum/forum_posts.asp?TID=3031&KW=DrawLine&PID=12210&title=slow-line-draw-speed#12210
http://www.quickpdf.org/forum/forum_posts.asp?TID=2776&KW=DrawLine&PID=11323&title=generated-pdf-files-are-too-large#11323
http://www.quickpdf.org/forum/forum_posts.asp?TID=3031&KW=DrawPath&PID=12213&title=slow-line-draw-speed#12213

Perhaps helping links:
http://www.quickpdf.org/forum/forum_posts.asp?TID=3010&KW=DrawPath&PID=12136&title=path-definition-and-drawing#12136
http://www.quickpdf.org/forum/forum_posts.asp?TID=2124&KW=DrawPath&PID=9040&title=how-to-draw-hatches#9040



-------------
Cheers,
Ingo



Posted By: fellafoo
Date Posted: 29 Jul 22 at 3:30PM
Thank you for your insight Tim.


Posted By: fellafoo
Date Posted: 29 Jul 22 at 3:31PM
Originally posted by Ingo Ingo wrote:

I'm not able to help but i've searched through the forum here regarding similar issues.
Perhaps the links below let you go a step ahead...
Thanks Ingo, I'll check these out.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk