Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
maniwani committed Nov 9, 2023
1 parent 5202c4e commit a8575de
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 152 deletions.
9 changes: 4 additions & 5 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ impl App {

// reassemble
*self = App::from_parts(sub_apps, tls, send, recv, runner);

self.remove_tls_channel();
}

/// Runs the [`App`] by calling its [runner](Self::set_runner).
Expand Down Expand Up @@ -927,9 +925,10 @@ impl App {
type RunnerFn = Box<dyn FnOnce(App)>;

fn run_once(mut app: App) {
let initial_plugins_state = app.plugins_state();

// wait for plugins to finish setting up
let plugins_state = app.plugins_state();
if plugins_state != PluginsState::Cleaned {
if app.plugins_state() != PluginsState::Cleaned {
while app.plugins_state() == PluginsState::Adding {
#[cfg(not(target_arch = "wasm32"))]
bevy_tasks::tick_global_task_pools_on_main_thread();
Expand All @@ -939,7 +938,7 @@ fn run_once(mut app: App) {
}

// If plugins where cleaned before the runner start, an update already ran
if plugins_state == PluginsState::Cleaned {
if initial_plugins_state == PluginsState::Cleaned {
return;
}

Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_app/src/schedule_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ impl Plugin for ScheduleRunnerPlugin {
let run_mode = self.run_mode;
app.set_runner(move |mut app: App| {
// wait for plugins to finish setting up
let plugins_state = app.plugins_state();
if plugins_state != PluginsState::Cleaned {
if app.plugins_state() != PluginsState::Cleaned {
while app.plugins_state() == PluginsState::Adding {
#[cfg(not(target_arch = "wasm32"))]
bevy_tasks::tick_global_task_pools_on_main_thread();
Expand All @@ -81,7 +80,7 @@ impl Plugin for ScheduleRunnerPlugin {
match run_mode {
RunMode::Once => {
// if plugins where cleaned before the runner start, an update already ran
if plugins_state != PluginsState::Cleaned {
if app.plugins_state() != PluginsState::Cleaned {
app.update();
}
}
Expand Down
4 changes: 0 additions & 4 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
#param::init_state(world, &mut #meta);
let #param = #param::init_state(world, &mut system_meta.clone());
)*
// Make the ParamSet non-send if any of its parameters are non-send.
if false #(|| !#meta.is_send())* {
system_meta.set_non_send();
}
#(
system_meta
.component_access_set
Expand Down
9 changes: 9 additions & 0 deletions crates/bevy_ecs/src/storage/resource_non_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,15 @@ impl ThreadLocalStorage {
TLS.with_borrow_mut(|tls| tls.resource_scope(f))
}

/// Runs `f` in a scope that has access to the thread-local resources.
pub fn run<F, T>(&mut self, f: F) -> T
where
F: FnOnce(&mut ThreadLocals) -> T,
T: 'static,
{
TLS.with_borrow_mut(|tls| f(tls))
}

/// Inserts a channel into `world` that systems in `world` (via [`ThreadLocal`]) can use to
/// access the underlying [`ThreadLocals`].
pub fn insert_channel<S>(&self, world: &mut World, sender: S)
Expand Down
30 changes: 0 additions & 30 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1506,34 +1506,4 @@ mod tests {
schedule.add_systems(non_sync_system);
schedule.run(&mut world);
}

// Regression test for https://github.com/bevyengine/bevy/issues/10207.
#[test]
fn param_set_non_send_first() {
fn non_send_param_set(mut p: ParamSet<(NonSend<*mut u8>, ())>) {
let _ = p.p0();
p.p1();
}

let mut world = World::new();
world.insert_non_send_resource(std::ptr::null_mut::<u8>());
let mut schedule = crate::schedule::Schedule::default();
schedule.add_systems((non_send_param_set, non_send_param_set, non_send_param_set));
schedule.run(&mut world);
}

// Regression test for https://github.com/bevyengine/bevy/issues/10207.
#[test]
fn param_set_non_send_second() {
fn non_send_param_set(mut p: ParamSet<((), NonSendMut<*mut u8>)>) {
p.p0();
let _ = p.p1();
}

let mut world = World::new();
world.insert_non_send_resource(std::ptr::null_mut::<u8>());
let mut schedule = crate::schedule::Schedule::default();
schedule.add_systems((non_send_param_set, non_send_param_set, non_send_param_set));
schedule.run(&mut world);
}
}
Loading

0 comments on commit a8575de

Please sign in to comment.