Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input): Remove SendWrapper from GILRS_CONTEXT (unless on wasm) #477

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion framework_crates/bones_framework/src/input/gilrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
use crate::prelude::*;
use gilrs::{ev::filter::axis_dpad_to_button, EventType, Filter, Gilrs as GilrsContext};
use once_cell::sync::Lazy;
use send_wrapper::SendWrapper;
use std::sync::{Arc, Mutex};

#[cfg(target_arch = "wasm32")]
use send_wrapper::SendWrapper;

/// Lazy-initialized GilrsContext
#[cfg(not(target_arch = "wasm32"))]
static GILRS_CONTEXT: Lazy<Arc<Mutex<GilrsContext>>> = Lazy::new(|| {
Arc::new(Mutex::new(
GilrsContext::new().expect("Failed to initialize GilrsContext"),
))
});

// Use SendWrapper when on wasm - GilrsContext is not Sync/Send on wasm,
// this is ok because bevy is single threaded on wasm, it will only be
// accessed from one thread.
/// Lazy-initialized GilrsContext
#[cfg(target_arch = "wasm32")]
static GILRS_CONTEXT: Lazy<Arc<Mutex<SendWrapper<GilrsContext>>>> = Lazy::new(|| {
Arc::new(Mutex::new(SendWrapper::new(
GilrsContext::new().expect("Failed to initialize GilrsContext"),
Expand Down
Loading