From 04aea4e9abb3c4ef063c3c473183b3b6c10ffc5f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 23 Jun 2019 08:29:47 -0700 Subject: [PATCH] Use `view` instead of `subarray` in WebGL example Pointed out in #1615! --- examples/webgl/src/lib.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/examples/webgl/src/lib.rs b/examples/webgl/src/lib.rs index 3328759e..f73532f4 100644 --- a/examples/webgl/src/lib.rs +++ b/examples/webgl/src/lib.rs @@ -1,4 +1,3 @@ -use js_sys::WebAssembly; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; use web_sys::{WebGlProgram, WebGlRenderingContext, WebGlShader}; @@ -37,15 +36,10 @@ pub fn start() -> Result<(), JsValue> { context.use_program(Some(&program)); let vertices: [f32; 9] = [-0.7, -0.7, 0.0, 0.7, -0.7, 0.0, 0.0, 0.7, 0.0]; - let memory_buffer = wasm_bindgen::memory() - .dyn_into::()? - .buffer(); - let vertices_location = vertices.as_ptr() as u32 / 4; - let vert_array = js_sys::Float32Array::new(&memory_buffer) - .subarray(vertices_location, vertices_location + vertices.len() as u32); let buffer = context.create_buffer().ok_or("failed to create buffer")?; context.bind_buffer(WebGlRenderingContext::ARRAY_BUFFER, Some(&buffer)); + let vert_array = unsafe { js_sys::Float32Array::view(&vertices) }; context.buffer_data_with_array_buffer_view( WebGlRenderingContext::ARRAY_BUFFER, &vert_array,