photon icon indicating copy to clipboard operation
photon copied to clipboard

Uncaught RuntimeError: unreachable in Node on multiple functions

Open coreyward opened this issue 3 years ago • 7 comments

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/[email protected]:

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).

coreyward avatar Aug 13 '22 21:08 coreyward

@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! 😄 👍

silvia-odwyer avatar Aug 14 '22 20:08 silvia-odwyer

@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 avatar Aug 14 '22 20:08 coreyward

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)

coreyward avatar Aug 14 '22 20:08 coreyward

@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! 😄 👍

silvia-odwyer avatar Aug 14 '22 22:08 silvia-odwyer

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?

coreyward avatar Aug 15 '22 17:08 coreyward

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! 😄 👍

silvia-odwyer avatar Aug 15 '22 19:08 silvia-odwyer

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,/, "");

allthesignals avatar Feb 05 '24 02:02 allthesignals