Skip to content

Commit 60a0638

Browse files
committed
Add console_error_panic_hook to examples
1 parent 67a4902 commit 60a0638

10 files changed

Lines changed: 30 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ criterion = { version = "0.8.1", default-features = false, features = [
154154

155155
[target.'cfg(target_family = "wasm")'.dev-dependencies]
156156
wasm-bindgen-test = "0.3"
157+
console_error_panic_hook = "0.1"
157158

158159
[target.'cfg(not(any(target_os = "android", target_vendor = "apple", target_os = "redox", target_family = "wasm", target_os = "windows")))'.dev-dependencies]
159160
rustix = { version = "1.0.1", features = ["event"] }

examples/animation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use winit::keyboard::{Key, NamedKey};
1010
mod util;
1111

1212
fn main() {
13+
util::setup();
14+
1315
let event_loop = EventLoop::new().unwrap();
1416
let start = Instant::now();
1517

examples/drm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Example of using softbuffer with drm-rs.
22
3+
mod util;
4+
35
#[cfg(all(
46
feature = "kms",
57
not(any(
@@ -237,5 +239,7 @@ mod imple {
237239
}
238240

239241
fn main() -> Result<(), Box<dyn std::error::Error>> {
242+
util::setup();
243+
240244
imple::entry()
241245
}

examples/fruit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use winit::keyboard::{Key, NamedKey};
77
mod util;
88

99
fn main() {
10+
util::setup();
11+
1012
//see fruit.jpg.license for the license of fruit.jpg
1113
let fruit = image::load_from_memory(include_bytes!("fruit.jpg")).unwrap();
1214
let (width, height) = (fruit.width(), fruit.height());

examples/libxcb.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Example of using `softbuffer` with `libxcb`.
22
3+
mod util;
4+
35
#[cfg(all(
46
feature = "x11",
57
not(any(
@@ -155,6 +157,8 @@ mod example {
155157
))
156158
))]
157159
fn main() {
160+
util::setup();
161+
158162
example::run();
159163
}
160164

@@ -169,5 +173,7 @@ fn main() {
169173
))
170174
)))]
171175
fn main() {
176+
util::setup();
177+
172178
eprintln!("This example requires the `x11` feature to be enabled on a supported platform.");
173179
}

examples/rectangle.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ fn redraw(buffer: &mut Buffer<'_, impl HasDisplayHandle, impl HasWindowHandle>,
2626
}
2727

2828
fn main() {
29+
util::setup();
30+
2931
let event_loop = EventLoop::new().unwrap();
3032
let context = softbuffer::Context::new(event_loop.owned_display_handle()).unwrap();
3133

examples/util/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
#[allow(dead_code)]
12
mod winit_app;
23

34
#[allow(unused_imports)]
45
pub use self::winit_app::*;
6+
7+
/// Set up the console error hook on WebAssembly.
8+
pub fn setup() {
9+
#[cfg(target_family = "wasm")]
10+
console_error_panic_hook::set_once();
11+
}

examples/winit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ mod util;
77

88
#[cfg(not(target_os = "android"))]
99
fn main() {
10+
util::setup();
11+
1012
entry(EventLoop::new().unwrap())
1113
}
1214

examples/winit_multithread.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! `Surface` implements `Send`. This makes sure that multithreading can work here.
22
3-
#[cfg(not(target_family = "wasm"))]
43
mod util;
54

65
#[cfg(not(target_family = "wasm"))]
@@ -134,6 +133,8 @@ mod ex {
134133

135134
#[cfg(not(target_os = "android"))]
136135
fn main() {
136+
util::setup();
137+
137138
use winit::event_loop::EventLoop;
138139
ex::entry(EventLoop::new().unwrap())
139140
}

examples/winit_wrong_sized_buffer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use winit::keyboard::{Key, NamedKey};
66
mod util;
77

88
fn main() {
9+
util::setup();
10+
911
let event_loop = EventLoop::new().unwrap();
1012
let context = softbuffer::Context::new(event_loop.owned_display_handle()).unwrap();
1113

0 commit comments

Comments
 (0)