Commit 228541b8 authored by Florian Blasius's avatar Florian Blasius 🤘

web: fix buffer len

parent 9761e933
Pipeline #9148 passed with stage
in 1 minute and 12 seconds
extern crate wasm_bindgen;
extern crate web_sys;
use std::{cell::{Cell, RefCell},
rc::Rc};
use std::{
cell::{Cell, RefCell},
rc::Rc,
};
use self::wasm_bindgen::{prelude::*, Clamped, JsCast};
use self::web_sys::{Document, HtmlCanvasElement, HtmlElement, Window as WebWindow};
......@@ -83,14 +85,11 @@ impl Renderer for Window {
/// Flip the window buffer
fn sync(&mut self) -> bool {
let bytes = self.data_mut();
let len = bytes.len() * std::mem::size_of::<Color>();
// converts the `Color` data to u8
let color_data = unsafe {
std::slice::from_raw_parts_mut(
bytes.as_mut_ptr() as *mut u8,
bytes.len() / std::mem::size_of::<u8>(),
)
};
let color_data =
unsafe { std::slice::from_raw_parts_mut(bytes.as_mut_ptr() as *mut u8, len) };
// crates a `ImageData` object from the window buffer and put it to the canvas.
if let Ok(image_data) =
......@@ -179,7 +178,7 @@ impl Window {
mode: Cell::new(Mode::Blend),
mouse_relative,
drop_content,
data: vec![Color::rgb(255, 255, 255); (w * h * 4) as usize],
data: vec![Color::rgb(255, 255, 255); (w * h) as usize],
canvas,
context,
events,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment