diff --git a/crates/demo/src/main.rs b/crates/demo/src/main.rs index ab073263..c35b41a1 100644 --- a/crates/demo/src/main.rs +++ b/crates/demo/src/main.rs @@ -32,25 +32,6 @@ async fn run(event_loop: EventLoop<()>, window: Window) { match event { Event::AboutToWait => { - #[cfg(target_arch = "wasm32")] - { - use winit::dpi::LogicalSize; - use winit::event::WindowEvent; - use winit::window::WindowId; - - let web_window = web_sys::window().unwrap(); - - let event: Event<'_, ()> = Event::WindowEvent { - window_id: unsafe { WindowId::dummy() }, - event: WindowEvent::Resized(window.inner_size()), - }; - - let width = web_window.inner_width().unwrap().as_f64().unwrap(); - let height = web_window.inner_height().unwrap().as_f64().unwrap(); - window.set_inner_size(LogicalSize::new(width, height)); - graphics.handle_event(&mut yak, &event, control_flow); - } - window.request_redraw(); } @@ -73,23 +54,25 @@ async fn run(event_loop: EventLoop<()>, window: Window) { fn main() { let event_loop = EventLoop::new().unwrap(); let window = winit::window::Window::new(&event_loop).unwrap(); + #[cfg(not(target_arch = "wasm32"))] { env_logger::init(); - // Temporarily avoid srgb formats for the swapchain on the web pollster::block_on(run(event_loop, window)); } + #[cfg(target_arch = "wasm32")] { + use winit::platform::web::WindowExtWebSys; + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); console_log::init().expect("could not initialize logger"); - use winit::platform::web::WindowExtWebSys; // On wasm, append the canvas to the document body web_sys::window() .and_then(|win| win.document()) .and_then(|doc| doc.body()) .and_then(|body| { - body.append_child(&web_sys::Element::from(window.canvas())) + body.append_child(&web_sys::Element::from(window.canvas().unwrap())) .ok() }) .expect("couldn't append canvas to document body"); diff --git a/crates/yakui-app/src/lib.rs b/crates/yakui-app/src/lib.rs index b549d0f2..465e9613 100644 --- a/crates/yakui-app/src/lib.rs +++ b/crates/yakui-app/src/lib.rs @@ -25,7 +25,14 @@ pub struct Graphics { impl Graphics { pub async fn new(window: &Window) -> Self { - let size = window.inner_size(); + let mut size = window.inner_size(); + + // FIXME: On web, we're receiving (0, 0) as the initial size of the + // window, which makes wgpu upset. If we hit that case, let's just make + // up a size and let it get fixed later. + if size == PhysicalSize::new(0, 0) { + size = PhysicalSize::new(800, 600); + } let instance = wgpu::Instance::default(); let surface =