image icon indicating copy to clipboard operation
image copied to clipboard

Uncaught (in promise) RuntimeError: unreachable

Open maninkari opened this issue 3 years ago • 15 comments

Hi, I am trying to use image and imageproc functions but keep getting in both cases a runtime error mentioning unreacheable. Any clues why this could be? I am compiling my code into wasm using cargo/wasm-pack. Thank you!

example:

let w = 200;
let h = 200;

let img = ImageBuffer::from_fn(w, h, |x, y| {
    if (x + y) % 3 == 0 {
        image::Rgba([0, 0, 0, 255])
    } else {
        image::Rgba([255, 255, 255, 255])
    }
});

img.save("out.png").unwrap();
Screenshot 2021-05-04 at 16 31 33

maninkari avatar May 04 '21 15:05 maninkari

I tried fixing the link but it appears to not have been uploaded successfully. Could you have a look and ensure that the image causing the error is available?

HeroicKatora avatar May 04 '21 15:05 HeroicKatora

Hi, thanks for looking into this. I just updated my initial comment.

maninkari avatar May 04 '21 16:05 maninkari

Weird, core::option::expect_none_failed is not what I would expect in a stacktrace that ends with unreachable. It seems like an assertion triggered (possibly this one) but the wasm compilation translates this to unreachable somehow. Did you compile with panic=abort?

HeroicKatora avatar May 06 '21 10:05 HeroicKatora

No, just wasm-pack build --target web

maninkari avatar May 06 '21 10:05 maninkari

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 40.028 USD (40.0 USD @ $1.0/USD) attached to it.

gitcoinbot avatar Feb 03 '22 18:02 gitcoinbot

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 1 month from now. Please review their action plans below:

1) zhyd1997 has started work.

try cargo 1.56.0 (4ed5d137b 2021-10-04) and ustup 1.24.3 (ce5817a94 2021-05-31)

Learn more on the Gitcoin Issue Details page.

gitcoinbot avatar Feb 03 '22 20:02 gitcoinbot

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 40.028 USD (40.0 USD @ $1.0/USD) has been submitted by:

  1. @zhyd1997

@birdlavv please take a look at the submitted work:

  • PR by @zhyd1997

gitcoinbot avatar Feb 03 '22 20:02 gitcoinbot

Apologies @zhyd1997, I was unable to get a working WASM package built with those specific versions of rustup and cargo and your PR.

I've made a reproduction repo here: https://github.com/birdlavv/image-rs-1471-reproduction

birdlavv avatar Feb 03 '22 21:02 birdlavv

@birdlavv So what're versions of rustup and cargo you used?

And node -v?

zhyd1997 avatar Feb 04 '22 01:02 zhyd1997

Here is mine: enviroments

zhyd1997 avatar Feb 04 '22 01:02 zhyd1997

Sorry @zhyd1997 for the miscommunication, I was unable to get the build working- after I had installed the versions you specified.

Here are my versions:

Screen Shot 2022-02-03 at 7 51 31 PM

birdlavv avatar Feb 04 '22 01:02 birdlavv

change your code like so, and reproduce as README described.

Screen Shot 2022-02-04 at 10 04 10 Screen Shot 2022-02-04 at 10 04 42

zhyd1997 avatar Feb 04 '22 02:02 zhyd1997

@birdlavv You can copy the code here: https://crates.io/crates/console_error_panic_hook

zhyd1997 avatar Feb 04 '22 02:02 zhyd1997

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


The funding of 40.028 USD (40.0 USD @ $1.0/USD) attached to this issue has been approved & issued to @zhyd1997.

gitcoinbot avatar Feb 04 '22 02:02 gitcoinbot

Aha! It the hook produces:

panicked at 'called `Result::unwrap()` on an `Err` value: IoError(Error { kind: Unsupported, message: "operation not supported on this platform" })', src/lib.rs:20:25

After removing the img.save("out.png").unwrap(); line it ran successfully!

I believe this is because WASM does not have access to the filesystem. Thanks @zhyd1997! Bounty paid & closed.

birdlavv avatar Feb 04 '22 02:02 birdlavv