pdfium-lib icon indicating copy to clipboard operation
pdfium-lib copied to clipboard

Get error "Uncaught RuntimeError: unreachable" when initialize

Open paulocoutinhox opened this issue 3 years ago • 10 comments

Describe the bug Hi,

Im getting this error: image

It happen when i call FPDF.Init().

It start happen only after use recent version of "emscripten". Im using now "2.0.34" (but tested with others) to keep it updated, but need solve this error.

To Reproduce

  1. Download latest pdfium from my branch: https://www.dropbox.com/s/n1bz12hcvif2h0a/artifact-wasm-4692.zip?dl=1
  2. Unzip it: unzip artifact-wasm-4692.zip
  3. Untar it: tar -xzvf wasm.tgz
  4. Execute: cd "release/node"
  5. Execute: python -m http.server
  6. Open in browser: http://localhost:8000/?debug=1
  7. Execute on browser console: FPDF.Init()

Expected behavior

Initialize PDFium without problems.

Screenshots

image

System (please complete the following information):

  • OS: [e.g. macos]
  • Version [e.g. bigsur]

paulocoutinhox avatar Nov 05 '21 23:11 paulocoutinhox

Hi,

@cetinsert can you help update to latest version?

I only need solve this problem.

paulocoutinhox avatar Nov 05 '21 23:11 paulocoutinhox

@paulo-coutinho – I am looking into it.

CetinSert avatar Nov 06 '21 00:11 CetinSert

Nice, thanks. Me too.

Im using docker to help compile from mac.

So, with these commands you can make fast tests like me:

docker run -v ${PWD}:/app -i -t=false pdfium-wasm python3 make.py run test-wasm
python -m http.server --directory sample-wasm/build

And only need open http://localhost:8000/?debug=1 in your browser.

It compile file main.cpp and you can play with it. I have commented all lines inside main method and the error still happen.

paulocoutinhox avatar Nov 06 '21 00:11 paulocoutinhox

People here https://github.com/emscripten-core/emscripten/issues/9443#issuecomment-594864722 (from the linked comment below) follow the same issue all the way up to LLVM.

CetinSert avatar Nov 06 '21 00:11 CetinSert

Hi,

The problem is in this line FPDF_InitLibraryWithConfig(&config);.

Im trying understand.

paulocoutinhox avatar Nov 06 '21 00:11 paulocoutinhox

Yes, it fails to return.

  • try the --profile flag to produce a better stack trace: https://github.com/emscripten-core/emscripten/issues/9443#issuecomment-594864722
  • try different optimization levels -O1 vs ...
    • https://github.com/emscripten-core/emscripten/issues/9443#issuecomment-821814373
    • https://github.com/emscripten-core/emscripten/issues/9443#issuecomment-823029438

CetinSert avatar Nov 06 '21 00:11 CetinSert

I tried all optimization levels, but still failling.

My stacktrace:

index.js:77 Uncaught RuntimeError: unreachable
    at pdfium::base::AllocPages(void*, unsigned long, unsigned long, pdfium::base::PageAccessibilityConfiguration, pdfium::base::PageTag, bool) (index.wasm:0x71085)
    at pdfium::base::internal::PartitionBucket::SlowPathAlloc(pdfium::base::internal::PartitionRootBase*, int, unsigned long, bool*) (index.wasm:0x72900)
    at fxcrt::StringDataTemplate<char>::Create(unsigned long) (index.wasm:0x5628)
    at fxcrt::StringDataTemplate<char>::Create(char const*, unsigned long) (index.wasm:0x5695)
    at fxcrt::ByteString::ByteString(char const*) (index.wasm:0x886e)
    at CLinuxPlatform::CreateDefaultSystemFontInfo() (index.wasm:0xf501)
    at CFX_GEModule::Create(char const**) (index.wasm:0x13666)
    at FPDF_InitLibraryWithConfig (index.wasm:0x70a9e)
    at main (index.wasm:0x367b)
    at index.js:1591
$pdfium::base::AllocPages(void*, unsigned long, unsigned long, pdfium::base::PageAccessibilityConfiguration, pdfium::base::PageTag, bool) @ index.wasm:0x71085
$pdfium::base::internal::PartitionBucket::SlowPathAlloc(pdfium::base::internal::PartitionRootBase*, int, unsigned long, bool*) @ index.wasm:0x72900
$fxcrt::StringDataTemplate<char>::Create(unsigned long) @ index.wasm:0x5628
$fxcrt::StringDataTemplate<char>::Create(char const*, unsigned long) @ index.wasm:0x5695
$fxcrt::ByteString::ByteString(char const*) @ index.wasm:0x886e
$CLinuxPlatform::CreateDefaultSystemFontInfo() @ index.wasm:0xf501
$CFX_GEModule::Create(char const**) @ index.wasm:0x13666
$FPDF_InitLibraryWithConfig @ index.wasm:0x70a9e
$main @ index.wasm:0x367b
(anonymous) @ index.js:1591
callMain @ index.js:5933
doRun @ index.js:5990
(anonymous) @ index.js:6001
setTimeout (async)
run @ index.js:5997
runCaller @ index.js:5911
removeRunDependency @ index.js:1520
receiveInstance @ index.js:1680
receiveInstantiationResult @ index.js:1697
Promise.then (async)
(anonymous) @ index.js:1726
Promise.then (async)
instantiateAsync @ index.js:1723
createWasm @ index.js:1754
(anonymous) @ index.js:5465

I change again to "2.0.24" to finish the PR and will open another PR to solve it.

paulocoutinhox avatar Nov 06 '21 00:11 paulocoutinhox

AllocPages is still being a source of suffering it seems o__O. Looking forward to https://github.com/paulo-coutinho/pdfium-lib/pull/55!

CetinSert avatar Nov 06 '21 05:11 CetinSert

I tried the same thing for emscripten 3.0.0 and this problem still :(

paulocoutinhox avatar Nov 28 '21 17:11 paulocoutinhox

I made a new branch only to test it: https://github.com/paulo-coutinho/pdfium-lib/tree/emscripten

I have updated to emscripten 3.1.0 and the same problem happen :(

paulocoutinhox avatar Dec 30 '21 04:12 paulocoutinhox

Hi,

All problems was fixed in new release.

You can check here: https://github.com/paulocoutinhox/pdfium-lib/releases/tag/5407

The demo is here: https://pdfviewer.github.io/

Feel free to donate to help project development.

Thanks.

paulocoutinhox avatar Nov 08 '22 18:11 paulocoutinhox