Skip to content

Commit f95c417

Browse files
committed
add system to tick local executors on main thread
1 parent bf883a1 commit f95c417

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

crates/bevy_core/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
mod name;
55
mod task_pool_options;
66

7+
use bevy_ecs::schedule::IntoSystemDescriptor;
78
use bevy_ecs::system::Resource;
9+
use bevy_ecs::world::World;
810
pub use bytemuck::{bytes_of, cast_slice, Pod, Zeroable};
911
pub use name::*;
1012
pub use task_pool_options::*;
@@ -17,6 +19,7 @@ pub mod prelude {
1719

1820
use bevy_app::prelude::*;
1921
use bevy_ecs::entity::Entity;
22+
use bevy_tasks::prelude::tick_global_task_pools_on_main_thread;
2023
use bevy_utils::{Duration, HashSet, Instant};
2124
use std::borrow::Cow;
2225
use std::ops::Range;
@@ -34,6 +37,13 @@ impl Plugin for CorePlugin {
3437
.unwrap_or_default()
3538
.create_default_pools();
3639

40+
// run function in an exclusive system to make sure it runs on main thread
41+
fn tick_local_executors(_world: &mut World) {
42+
tick_global_task_pools_on_main_thread();
43+
}
44+
45+
app.add_system_to_stage(bevy_app::CoreStage::Last, tick.at_end());
46+
3747
app.register_type::<Entity>().register_type::<Name>();
3848

3949
register_rust_types(app);

crates/bevy_tasks/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ pub mod prelude {
2929
pub use crate::{
3030
iter::ParallelIterator,
3131
slice::{ParallelSlice, ParallelSliceMut},
32-
usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool},
32+
usages::{
33+
tick_global_task_pools_on_main_thread, AsyncComputeTaskPool, ComputeTaskPool,
34+
IoTaskPool,
35+
},
3336
};
3437
}
3538

0 commit comments

Comments
 (0)