not crashing

0.19
Benjamin Hansen 2 months ago
parent 6325590051
commit 3e618336bd

@ -13,7 +13,7 @@ pub fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init_with_level(log::Level::Warn).expect("Couldn't initialize logger");
console_log::init_with_level(log::Level::Debug).expect("Couldn't initialize logger");
} else {
env_logger::init();
}
@ -27,7 +27,7 @@ pub fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
@ -43,6 +43,9 @@ pub fn run() {
event_loop
.run(move |event, control_flow| match event {
Event::Resumed => {
log::debug!("Resumed");
}
Event::WindowEvent {
ref event,
window_id,

@ -85,7 +85,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
view_formats: vec![],
};
surface.configure(&device, &config);
let clear_color = wgpu::Color::BLACK;

@ -29,7 +29,7 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::all(),
backends: wgpu::Backends::PRIMARY,
..Default::default()
});
@ -83,7 +83,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
view_formats: vec![],
};
surface.configure(&device, &config);
Self {
surface,
@ -161,7 +160,7 @@ pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init_with_level(log::Level::Warn).expect("Couldn't initialize logger");
console_log::init_with_level(log::Level::Info).expect("Couldn't initialize logger");
} else {
env_logger::init();
}
@ -175,7 +174,6 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
//window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
use winit::platform::web::WindowExtWebSys;
web_sys::window()
@ -187,6 +185,8 @@ pub async fn run() {
Some(())
})
.expect("Couldn't append canvas to document body.");
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
}
// State::new uses async code, so we're going to wait for it to finish
@ -213,6 +213,7 @@ pub async fn run() {
..
} => control_flow.exit(),
WindowEvent::Resized(physical_size) => {
log::info!("physical_size: {physical_size:?}");
state.resize(*physical_size);
}
WindowEvent::RedrawRequested => {

@ -79,7 +79,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),

@ -81,7 +81,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
@ -233,7 +232,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -146,7 +146,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),

@ -142,7 +142,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
@ -311,7 +310,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -147,7 +147,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {

@ -143,7 +143,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let diffuse_bytes = include_bytes!("happy-tree.png");
let diffuse_texture =
@ -357,7 +356,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -293,7 +293,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let diffuse_bytes = include_bytes!("happy-tree.png");
let diffuse_texture =

@ -293,7 +293,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let diffuse_bytes = include_bytes!("happy-tree.png");
let diffuse_texture =
@ -566,7 +565,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -347,7 +347,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let diffuse_bytes = include_bytes!("happy-tree.png");
let diffuse_texture =

@ -354,7 +354,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let diffuse_bytes = include_bytes!("happy-tree.png");
let diffuse_texture =
@ -664,7 +663,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -546,7 +546,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let diffuse_bytes = include_bytes!("happy-tree.png");
let diffuse_texture =

@ -364,7 +364,6 @@ impl<'a> State<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let diffuse_bytes = include_bytes!("happy-tree.png");
let diffuse_texture =
@ -691,7 +690,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -308,7 +308,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@ -588,7 +587,7 @@ pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init_with_level(log::Level::Warn).expect("Could't initialize logger");
console_log::init_with_level(log::Level::Info).expect("Could't initialize logger");
} else {
env_logger::init();
}
@ -606,7 +605,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -122,7 +122,6 @@ where
camera_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
log::warn!("materials: {}", model.materials.len());
let material = &model.materials[mesh.material];
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group);
}

@ -144,6 +144,7 @@ pub async fn load_model(
usage: wgpu::BufferUsages::INDEX,
});
log::info!("{}", m.name);
model::Mesh {
name: file_name.to_string(),
vertex_buffer,

@ -16,8 +16,8 @@ impl Texture {
label: &str,
) -> Self {
let size = wgpu::Extent3d {
width: config.width,
height: config.height,
width: config.width.max(1),
height: config.height.max(1),
depth_or_array_layers: 1,
};
let desc = wgpu::TextureDescriptor {

@ -400,7 +400,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@ -743,7 +742,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -400,7 +400,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@ -794,7 +793,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -280,7 +280,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@ -697,7 +696,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -299,7 +299,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@ -827,7 +826,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -281,7 +281,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@ -747,7 +746,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -219,7 +219,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {

@ -85,7 +85,6 @@ impl<'a> Display<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
Ok(Self {
surface,

@ -285,7 +285,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@ -743,7 +742,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -87,7 +87,6 @@ impl<'a> Render<'a> {
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[],

@ -279,7 +279,6 @@ impl<'a> State<'a> {
view_formats: vec![],
};
surface.configure(&device, &config);
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@ -704,7 +703,7 @@ pub async fn run() {
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -181,7 +181,7 @@ Next, after we create our event loop and window, we need to add a canvas to the
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.request_inner_size(PhysicalSize::new(450, 400)).unwrap();
let _ = window.request_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()

@ -175,7 +175,6 @@ The `limits` field describes the limit of certain types of resources that we can
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
```
Here we are defining a config for our surface. This will define how the surface creates its underlying `SurfaceTexture`s. We will talk about `SurfaceTexture` when we get to the `render` function. For now, let's talk about the config's fields.

Loading…
Cancel
Save