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

Uncaught RuntimeError: unreachable in Node on multiple functions #134

Open
coreyward opened this issue Aug 13, 2022 · 7 comments
Open

Uncaught RuntimeError: unreachable in Node on multiple functions #134

coreyward opened this issue Aug 13, 2022 · 7 comments

Comments

@coreyward
Copy link

coreyward commented Aug 13, 2022

I'm unable to create a new PhotonImage from a base64 encoded string, or export an existing PhotonImage to base64 in a Node environment using @silvia-odwyer/photon-node@0.3.1:

const photon = require("@silvia-odwyer/photon-node")
const img = new photon.PhotonImage([], 10, 10)
img.get_base64()

Uncaught RuntimeError: unreachable
at wasm://wasm/003bcd4e:wasm-function[840]:0xc5801
at wasm://wasm/003bcd4e:wasm-function[961]:0xcae0e
at wasm://wasm/003bcd4e:wasm-function[1296]:0xd1ff3
at wasm://wasm/003bcd4e:wasm-function[1209]:0xd0e39
at wasm://wasm/003bcd4e:wasm-function[1298]:0xd2057
at wasm://wasm/003bcd4e:wasm-function[1159]:0xd00d1
at wasm://wasm/003bcd4e:wasm-function[755]:0xc07ec
at wasm://wasm/003bcd4e:wasm-function[104]:0x59665

// where `data` is a valid base64 string representing a JPEG image
img = photon.base64_to_image(data)
// or
img = photon.PhotonImage.new_from_base64(data)

Uncaught RuntimeError: unreachable
at wasm://wasm/003bcd4e:wasm-function[840]:0xc5801
at wasm://wasm/003bcd4e:wasm-function[961]:0xcae35
at wasm://wasm/003bcd4e:wasm-function[1296]:0xd1ff3
at wasm://wasm/003bcd4e:wasm-function[1209]:0xd0e39
at wasm://wasm/003bcd4e:wasm-function[1298]:0xd2057
at wasm://wasm/003bcd4e:wasm-function[994]:0xcbf23
at wasm://wasm/003bcd4e:wasm-function[805]:0xc37f0
at wasm://wasm/003bcd4e:wasm-function[1063]:0xcde2c
at wasm://wasm/003bcd4e:wasm-function[495]:0xab355

This happens in both Node 14.x and 16.x in both Intel and Apple Silicon environments (both macOS).

@silvia-odwyer
Copy link
Owner

silvia-odwyer commented Aug 14, 2022

@coreyward Hi Corey! Thanks for opening this issue. It's mentioned that you're using photon, however there is a separate library photon-node for Node environments, linked here. Could you try this and see if it works? If not, could you provide the image or base64 string also, as it would help diagnose the issue. Thanks very much! 😄 👍

@coreyward
Copy link
Author

@silvia-odwyer Oops that was just a typo in my post. I'm using photon-node in my code. I don't think the base64 string matters here as it happens even with this 3-line example going the other direction:

const photon = require("@silvia-odwyer/photon-node")
const img = new photon.PhotonImage([], 10, 10)
img.get_base64()

For reference, this occurred with every base64 string I tried, and I verified syntax on several by doing pbpaste | base64 --decode > test.jpg and confirming that the file operated like normal (e.g. in Preview/QuickLook).

@coreyward
Copy link
Author

coreyward commented Aug 14, 2022

Here's a CodeSandbox example demonstrating the issue. It actually seems to work fine when creating the image from the PNG data, but the JPG fails.

This is the source of the PNG. I convert it to JPEG using some built-in routine in Finder, resulting in the image attached here, for reference:

Red_Square_(2x2_Pixel)

@silvia-odwyer
Copy link
Owner

silvia-odwyer commented Aug 14, 2022

@coreyward Thanks very much for the CodeSandbox example, it's much appreciated! 👍 I've taken a look at the issue, and it seems to be linked to Issue #120. The rayon feature seems to be causing the bug in relation to creating jpeg images from base64.

To fix this, I've just published a new build. Could you update your photon-node dependency to 0.3.2 and let me know if it solves the issue? Thanks very much! 😄 👍

@coreyward
Copy link
Author

Thank you! It looks like this allows const img = photon.PhotonImage.new_from_base64(redSquareJpgB64); to succeed 🎉 , but calling img.get_image_data() or photon.get_image_data(img) on the result results in the same “unreachable” error. Calling photon.grayscale(img) like the guide shows results in “Uncaught: Error: recursive use of an object detected which would lead to unsafe aliasing in rust”. Am I doing something wrong here?

@silvia-odwyer
Copy link
Owner

Hi Corey,
I've just ran the example mentioned in the guide here, and it worked as expected. However when I included a line to get the image data, it did result in an unreachable error. I'll have to investigate why that is, although creating png/jpg images with base64 and writing the output is all working okay for me.

If you can't seem to apply effects etc, just include a code snippet and I'll try help out! 😄 👍

@allthesignals
Copy link

allthesignals commented Feb 5, 2024

Hi there, I'm also seeing this via get_image_data using ^0.3.3:

    const base64 = fs.readFileSync(imagePath, { encoding: 'base64' });
    const data = base64.replace(/^data:image\/(png|jpg);base64,/, "");
    const phtn_img = photon.PhotonImage.new_from_base64(data);
    photon.laplace(phtn_img)
    phtn_img.get_image_data();

RuntimeError: unreachable
at wasm://wasm/0052704a:wasm-function[1043]:0xf0618
at wasm://wasm/0052704a:wasm-function[1159]:0xf5558
at wasm://wasm/0052704a:wasm-function[1359]:0xfb0dc
at wasm://wasm/0052704a:wasm-function[1520]:0xfdf67
at wasm://wasm/0052704a:wasm-function[1204]:0xf6eec
at wasm://wasm/0052704a:wasm-function[1157]:0xf5437
at PhotonImage.get_image_data (/Users/mattgardner/archive-dol-arpa-income-verification/app/node_modules/@silvia-odwyer/photon-node/photon_rs.js:3905:24)

EDIT: Okay... I think this is a buried error over needing to apply another .replace(/^data:image\/(png|jpg);base64,/, "");

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

3 participants