Repository: image-rs/image

Issue #1496: The global thread pool has not been initialized.: ThreadPoolBuildError { kind: IOError(Error { kind: Unsupported, message: "operation not supported on this platform" }) }
Created: 2021-06-21T16:39:33Z
I'm trying to decode a JPEG image from a Vec u8, this Vec u8 comes from a javascript Uint8Array, as I'm trying to process an image in rust through WebAssembly, but I'm getting the following error:
panicked at 'The global thread pool has not been initialized.: ThreadPoolBuildError { kind: IOError(Error { kind: Unsupported, message: "operation not supported on this platform" }) }', C:\rust\cargo\registry\src\github.com-1ecc6299db9ec823\rayon-core-1.9.1\src\registry.rs:170:10

Stack:

Error
    at http://localhost:8000/photon_rs.js:4062:27
    at logError (http://localhost:8000/photon_rs.js:271:22)
    at imports.wbg.__wbg_new_59cb74e423758ede (http://localhost:8000/photon_rs.js:4061:20)
    at console_error_panic_hook::Error::new::hca09d9bc57ad3dd0 (http://localhost:8000/photon_rs_bg.wasm:wasm-function[16077]:0x65f468)
    at console_error_panic_hook::hook_impl::ha8bcc4998f07b33e (http://localhost:8000/photon_rs_bg.wasm:wasm-function[2698]:0x479ee0)
    at console_error_panic_hook::hook::hffcf27262a2014ba (http://localhost:8000/photon_rs_bg.wasm:wasm-function[17303]:0x670899)
    at core::ops::function::Fn::call::ha6f793f965b7e004 (http://localhost:8000/photon_rs_bg.wasm:wasm-function[15124]:0x6504dd)
    at std::panicking::rust_panic_with_hook::hbdbceb5cd158bf19 (http://localhost:8000/photon_rs_bg.wasm:wasm-function[5604]:0x546d8b)
    at std::panicking::begin_panic_handler::{{closure}}::h9995bb2f0de4bb38 (http://localhost:8000/photon_rs_bg.wasm:wasm-function[7694]:0x5a027c)
    at std::sys_common::backtrace::__rust_end_short_backtrace::hc7608161a467c002 (http://localhost:8000/photon_rs_bg.wasm:wasm-function[18481]:0x67f755)

use base64::{decode, encode};
use image::DynamicImage::ImageRgba8;
use image::{GenericImage, GenericImageView};

use image::io::Reader  as ImageReader; 
use image::ImageFormat;
use std::io::Cursor;

use js_sys::ArrayBuffer;
use js_sys::Uint8Array;
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;
use wasm_bindgen::Clamped;
use web_sys::{Blob, CanvasRenderingContext2d, HtmlCanvasElement, ImageData};

/// open image from a Uint8Array;
#[wasm_bindgen]
pub fn open_image_from_array_buffer(uint8array: Uint8Array) {
 
    console_log!("open_image_from_array_buffer {:?}", uint8array); //ok
 
    let raw_data: Vec<u8> = uint8array.to_vec(); //ok

    console_log!("open_image_from_array_buffer {:?}", raw_data); //ok  
    
    let image = ImageReader::with_format(Cursor::new(raw_data), ImageFormat::Jpeg).decode(); //error

    console_log!("open_image_from_array_buffer {:?}", image);  
   
}
https://github.com/insinfo/photon-test

Duplicate issue #1588: emscrioten and wasm .. seems to expect rayon+threads
Created: 2021-10-28T04:41:40Z
has this crate been used in the browser?
my project uses the image crate and is being ported to wasm32/emscrioten;
it crashes on startup reporting that threads arent available;
i can get it past that using “default-features = false” but then its not managung to decode textures (as far as i can tell)
Q1 could anyone verify if this should work
Q2 could the library default to no threading on the wasm targets
whats the thinking on this

Closing comment (2021-10-28T05:38:04Z): duplicate of #1496
You probably need to re-enable some of the features disabled by default-features = false to regain the support for decoding your textures, just don't enable the threading/rayon features.