wxpdfdoc icon indicating copy to clipboard operation
wxpdfdoc copied to clipboard

too many open filehandles

Open gfpos opened this issue 5 years ago • 1 comments

this is from using templates:

            pdfOut.AddPage();
            tpl = pdfOut.ImportPage( i );
            pdfOut.UseTemplate( tpl );

works fine as long as i am using less then 512 files. above that number my program crashes. Reason is: windows-7 has a maximum of 512 open files by default. you can increase that number easily by - _setmaxstdio (2048) - , but it would be better just to close the handle after assigning the template to the new PDF, because this is just another limitation. there should be no such limitation of files in general

btw: great job

gfpos avatar May 17 '19 12:05 gfpos

Unfortunately this issue is not as easy to fix. Although the content of a template is inserted immediately on calling UseTemplate, the template may reference resources (like graphics or fonts) which have to be extracted from the PDF source file, too, later on. In the current version of wxPdfDocument such resources are extracted only when finishing the resulting PDF document. The reason is that only then it is known which resources from a certain PDF source file are actually required.

To overcome the issue it would be necessary to temporarily close a source PDF file when it is no longer used and to reopen it while finalizing the resulting PDF document. Since several pages could be extracted from a source PDF file and templates could be used more than once, the user would have to tell wxPdfDocument when he doesn't want to access a certain source PDF file any longer.

Reinitializing the PDF parser associated to a certain PDF source file is not trivial, and processing more than 512 (or even 2048) PDF source files for a single resulting PDF document represents an uncommon special case. Therefore I fear I will not be able to provide a solution in the near future.

I have plans to overhaul wxPdfDocument in the future and will then certainly address this issue as well.

In the meantime it would probably make sense to adjust wxPdfDocument if necessary, so that it detects situation when the limit of open files is reached. Maybe you could provide additional information about your program's crash, allowing to identify the code in wxPdfDocument leading to the crash. Thanks.

utelle avatar May 17 '19 20:05 utelle