From 441456d2a566086f0848fb5117ae50846c8f0997 Mon Sep 17 00:00:00 2001 From: Mike Hsu Date: Sun, 5 May 2024 16:12:13 -0700 Subject: [PATCH] migrate bevy log's usage of non send resource --- crates/bevy_log/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/bevy_log/src/lib.rs b/crates/bevy_log/src/lib.rs index f37f0729a847e..7a9a8492870f0 100644 --- a/crates/bevy_log/src/lib.rs +++ b/crates/bevy_log/src/lib.rs @@ -54,6 +54,15 @@ use tracing_log::LogTracer; #[cfg(feature = "tracing-chrome")] use tracing_subscriber::fmt::{format::DefaultFields, FormattedFields}; use tracing_subscriber::{prelude::*, registry::Registry, EnvFilter}; +#[cfg(feature = "tracing-chrome")] +use {bevy_ecs::system::Resource, bevy_utils::synccell::SyncCell}; + +/// Wrapper resource for `tracing-chrome`'s flush guard. +/// When the guard is dropped the chrome log is written to file. +#[cfg(feature = "tracing-chrome")] +#[allow(dead_code)] +#[derive(Resource)] +pub(crate) struct FlushGuard(SyncCell); /// Adds logging to Apps. This plugin is part of the `DefaultPlugins`. Adding /// this plugin will setup a collector appropriate to your target platform: @@ -177,7 +186,7 @@ impl Plugin for LogPlugin { } })) .build(); - app.insert_non_send_resource(guard); + app.insert_resource(FlushGuard(SyncCell::new(guard))); chrome_layer };