Skip to content

Instantly share code, notes, and snippets.

@whistlegraph
Created July 20, 2018 22:49
Show Gist options
  • Save whistlegraph/fa4e74d39e1b3588a02d4c0d0474b37c to your computer and use it in GitHub Desktop.
Save whistlegraph/fa4e74d39e1b3588a02d4c0d0474b37c to your computer and use it in GitHub Desktop.
WASM Pixel Manipulation
static mut PIXELS: [u8; 128 * 128 * 4] = [0; 128 * 128 * 4];
#[no_mangle]
pub fn update_pixels() {
// How to remove this unsafe block?
unsafe {
PIXELS[0] = 255;
PIXELS[1] = 255;
PIXELS[2] = 0;
PIXELS[3] = 255;
}
}
#[no_mangle]
pub fn get_pixels() -> &'static [u8; 128 * 128 * 4] {
unsafe { &PIXELS }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment