Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM example not working with Pdfium release V5668 due to malloc() function change #95

Closed
inzanez opened this issue Jul 19, 2023 · 10 comments
Assignees

Comments

@inzanez
Copy link

inzanez commented Jul 19, 2023

I just tried running the WASM example and I always get Initialization of pdfium-render failed!. I used to build everything manually so far with emscripten which is quite a pain. Now it feels more like magic, but...can't tell why that wouldn't work.

Addition: I do get an error about malloc not being defined:
pdfium-render::initialize_pdfium_render(): Module._malloc() not defined. I guess that will be related to the actual wasm build?

@ajrcarey
Copy link
Owner

Hi @inzanez , thank you for reporting the problem. Can I check the following:

@inzanez
Copy link
Author

inzanez commented Jul 19, 2023

@ajrcarey hm,...I have been using the latest build of Pdfium (V5668)

Switching to the version that you mentioned fixed the issue. Is there any versioning hint or similar that would point out what version works? Not sure, maybe I missed something here. But great solution anyway! :-)

@ajrcarey
Copy link
Owner

ajrcarey commented Jul 19, 2023

No, there isn't any versioning hint, and annoyingly Pdfium itself doesn't provide any function to return the library version :/

I wouldn't describe this as a "solution" exactly, more a work-around. The problem is that the emscripten-provided malloc() function has changed in some way, although glancing at the function table for the latest Pdfium WASM build I don't immediately see any obvious problem.

Probably something subtle changed in the emscripten packaging, and it's just a question of tracking down what it was and figuring out how to work around it in pdfium-render. I'll leave this issue open to work on that. But for now you have a work-around: use an older library version!

@ajrcarey ajrcarey changed the title Wasm example not working out WASM example not working in release V5668 due to malloc() function change Jul 19, 2023
@ajrcarey ajrcarey self-assigned this Jul 19, 2023
@ajrcarey ajrcarey changed the title WASM example not working in release V5668 due to malloc() function change WASM example not working with Pdfium release V5668 due to malloc() function change Jul 19, 2023
@inzanez
Copy link
Author

inzanez commented Jul 19, 2023

Perfect, many thanks for that insight! I hope I can join you soon on digging into that issue. Sounds really interesting, but not that easy, remembering the whole emscripten around :-)

@ajrcarey
Copy link
Owner

ajrcarey commented Jul 19, 2023

The emscripten wrappers are in the pdfium.js file. Best guess is that the definition of Module._malloc() has changed in there in a recent WASM build of Pdfium compared to older releases. I'll try to take a look at it over the weekend.

@ajrcarey
Copy link
Owner

ajrcarey commented Jul 19, 2023

The pdfium.js file from V5407 contains the following export:

var _malloc=Module["_malloc"]=createExportWrapper("malloc")

But the pdfium.js file from V5668 has only the following:

var _malloc=createExportWrapper("malloc")

The missing Module["_malloc"]= is the source of the problem. Changing this to match V5407's pdfium.js resolves the problem. The same adjustment needs to be made for the free function.

@inzanez
Copy link
Author

inzanez commented Jul 20, 2023

@ajrcarey I would assume that must be updated in src/wasm.rs, right? The link to _malloc and _link...

@ajrcarey
Copy link
Owner

The createExportWrapper() function in emscripten's pdfium.js looks like it returns a reference to Module["asm"][<function name>]. It might be possible to use that internally in src/wasm.rs instead of Module["_malloc"], etc.

ajrcarey pushed a commit that referenced this issue Jul 30, 2023
@ajrcarey
Copy link
Owner

Adjusted PdfiumRenderWasmState::bind_to_pdfium() to use Module["asm"]["malloc"] and Module["asm"]["free"] in the event Module["_malloc"] and Module["_free"] are not available directly. Updated README. Ready to release as part of crate version 0.8.8.

@ajrcarey
Copy link
Owner

ajrcarey commented Aug 3, 2023

As there have been no further comments and I believe the issue is now resolved, I am closing the issue and publishing release 0.8.8. Feel free to re-open if you do not believe the issue is resolved in release 0.8.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants