Recent

Author Topic: pdfium.dll loadfromfile floating point error  (Read 2336 times)

kjteng

  • Sr. Member
  • ****
  • Posts: 259
pdfium.dll loadfromfile floating point error
« 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?

af0815

  • Hero Member
  • *****
  • Posts: 1380
Re: pdfium.dll loadfromfile floating point error
« Reply #1 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.
regards
Andreas

Thaddy

  • Hero Member
  • *****
  • Posts: 16201
  • Censorship about opinions does not belong here.
Re: pdfium.dll loadfromfile floating point error
« Reply #2 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!
« Last Edit: March 01, 2023, 07:52:28 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

paweld

  • Hero Member
  • *****
  • Posts: 1268
Best regards / Pozdrawiam
paweld

kjteng

  • Sr. Member
  • ****
  • Posts: 259
Re: pdfium.dll loadfromfile floating point error
« Reply #4 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 :-(
     



kjteng

  • Sr. Member
  • ****
  • Posts: 259
Re: pdfium.dll loadfromfile floating point error
« Reply #5 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?

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: pdfium.dll loadfromfile floating point error
« Reply #6 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. 
Best regards / Pozdrawiam
paweld

kjteng

  • Sr. Member
  • ****
  • Posts: 259
Re: pdfium.dll loadfromfile floating point error
« Reply #7 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

kjteng

  • Sr. Member
  • ****
  • Posts: 259
Re: pdfium.dll loadfromfile floating point error
« Reply #8 on: March 23, 2023, 01:51:25 pm »
I have modified the codes from  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.

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: pdfium.dll loadfromfile floating point error
« Reply #9 on: March 23, 2023, 02:14:41 pm »
I have modified the codes from  https://github.com/ahausladen/PdfiumLib   
Great! Now we need someone to prepare .obj files instead of .dlls.

kjteng

  • Sr. Member
  • ****
  • Posts: 259
Re: pdfium.dll loadfromfile floating point error
« Reply #10 on: March 26, 2023, 09:43:41 am »
.obj files... May i know what are you referriing to?

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: pdfium.dll loadfromfile floating point error
« Reply #11 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'}

kjteng

  • Sr. Member
  • ****
  • Posts: 259
Re: pdfium.dll loadfromfile floating point error
« Reply #12 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

Hopefully someone with better knowledge and skill can resolve this.

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: pdfium.dll loadfromfile floating point error
« Reply #13 on: March 28, 2023, 09:45:22 am »
I see. Seems DLLs will have to suffice :)

 

TinyPortal © 2005-2018