Lazarus

Announcements => Third party => Topic started by: kjteng on March 01, 2023, 03:14:36 am

Title: pdfium.dll loadfromfile floating point error
Post by: kjteng on March 01, 2023, 03:14:36 am
I am using pdfium.dll and the viewer component from https://github.com/pvginkel/PdfiumViewer.
Everytime I call pdfcontrol.LoadFromfile, i got this error:  External: FLT INEXACT RESULT
Based on my guess of this error,  I mask the floating point exception (SetExceptionMask([ exPrecision ]) and I managed to
loadFromFile without fail.
My question: what causes the error? There is no computation involves in opening the file (it cannot even open a pdf file which contain only a blank page).  Is there anyway to solve this problem without masking the fp error?
Title: Re: pdfium.dll loadfromfile floating point error
Post by: af0815 on March 01, 2023, 07:07:44 am
I think it is a good idea to ask the creator of the lib direct. Only the owner of the code can change, why a exception raise and can go across lib boundaries.

But the project is archived and discontinued.
Title: Re: pdfium.dll loadfromfile floating point error
Post by: Thaddy on March 01, 2023, 07:36:25 am
This error is caused by overzealous optimisation by Microsoft compilers. It is rather common for programs written in other compiler brands to encounter this. And indeed, masking out float exceptions is the recommended work-around. There is otherwise nothing you can do about it, apart from recompiling if you have the source. It also often happen with COM libraries. Afaik. it is only a problem with 32 bit dll's and only if the library is compiled by a Microsoft compiler.
What actually happens is that MS found it a good idea to use fpu registers as scratch on very high optimization settings, hence most Windows dll's just work since ms does usually not use those extreme optimizations themselves.
Also note as you observed: the code - in the dll - does not even have to have any floating point operations in it!
Title: Re: pdfium.dll loadfromfile floating point error
Post by: paweld on March 01, 2023, 08:02:16 am
Try this: https://forum.lazarus.freepascal.org/index.php/topic,58056.msg432524.html#msg432524
Title: Re: pdfium.dll loadfromfile floating point error
Post by: kjteng on March 01, 2023, 09:48:16 am
Thanks for all the replies and explanation.

I tried the sample project1.zip as suggested by paweld.  Same outcome.

However I also noticed that if I use back an older version of pdfium.dll (dated 2017-03-17), there wont be such error.  Only new release of pdfium.dll (64bit) after 2017 have this error.
Perhaps the best solution (like what mentioned by af0815 and Thaddy is to make correct and recompile it from the source ... only people who are familiar with c/c++ can do this :-(
     


Title: Re: pdfium.dll loadfromfile floating point error
Post by: kjteng on March 03, 2023, 02:47:51 am
Try this: https://forum.lazarus.freepascal.org/index.php/topic,58056.msg432524.html#msg432524
@paweld, may i know where are the codes for tbe three pfium components from?  Can i use it in my application? What is the licence type?
Title: Re: pdfium.dll loadfromfile floating point error
Post by: paweld on March 03, 2023, 06:46:45 am
Files Pdfium*.pas I found on this forum, unfortunately I do not remember exactly in whose post. On the other hand, I managed to track down the original author of the component: https://github.com/ahausladen/PdfiumLib   
files in the project is an older version of the component with some changes to adapt the component to lazarus. 
Title: Re: pdfium.dll loadfromfile floating point error
Post by: kjteng on March 03, 2023, 11:46:36 am
Files Pdfium*.pas I found on this forum, unfortunately I do not remember exactly in whose post. On the other hand, I managed to track down the original author of the component: https://github.com/ahausladen/PdfiumLib   
files in the project is an older version of the component with some changes to adapt the component to lazarus.
Thank you for the info. If i m not mistaken, it should be MPL
Title: Re: pdfium.dll loadfromfile floating point error
Post by: kjteng on March 23, 2023, 01:51:25 pm
I have modified the codes from  https://github.com/ahausladen/PdfiumLib   
 (https://github.com/ahausladen/PdfiumLib) for it to work in my personal projects written lazarus/freepascal. The free pascal port (windows only) is available at https://github.com/kjteng/PdfiumLib/
I have also uploaded a few examples to illustrate the functions relating to attachment file, weblinks, text search/replace and fillable form.
You are welcome to download and test it. Thank you.
Title: Re: pdfium.dll loadfromfile floating point error
Post by: domasz on March 23, 2023, 02:14:41 pm
I have modified the codes from  https://github.com/ahausladen/PdfiumLib   
 (https://github.com/ahausladen/PdfiumLib)
Great! Now we need someone to prepare .obj files instead of .dlls.
Title: Re: pdfium.dll loadfromfile floating point error
Post by: kjteng on March 26, 2023, 09:43:41 am
.obj files... May i know what are you referriing to?
Title: Re: pdfium.dll loadfromfile floating point error
Post by: domasz on March 26, 2023, 05:21:00 pm
.obj files... May i know what are you referriing to?
Right, sorry. In Delphi static linking uses .obj files. In Lazarus it's .ppu and .o:
Code: Pascal  [Select][+][-]
  1. {$L 'library.obj'}
Title: Re: pdfium.dll loadfromfile floating point error
Post by: kjteng on March 28, 2023, 08:32:26 am
Right, sorry. In Delphi static linking uses .obj files. In Lazarus it's .ppu and .o:
Code: Pascal  [Select][+][-]
  1. {$L 'library.obj'}
Oh you mean you want to statically link pdfium? I thuoght of that before but I think is beyong my ability. Also refer to the following link:
https://github.com/bblanchon/pdfium-binaries/issues/84 (https://github.com/bblanchon/pdfium-binaries/issues/84)

Hopefully someone with better knowledge and skill can resolve this.
Title: Re: pdfium.dll loadfromfile floating point error
Post by: domasz on March 28, 2023, 09:45:22 am
I see. Seems DLLs will have to suffice :)
TinyPortal © 2005-2018