From 206d2dbe8cf1ff019a8e1cdc2a07065c3a343972 Mon Sep 17 00:00:00 2001 From: Pixelstorm Date: Sun, 21 Jan 2024 00:21:01 +0000 Subject: [PATCH 1/3] Impl debug on CommandQueue --- crates/bevy_ecs/src/system/commands/command_queue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/system/commands/command_queue.rs b/crates/bevy_ecs/src/system/commands/command_queue.rs index 5130089cc8fd2..817c580831ce4 100644 --- a/crates/bevy_ecs/src/system/commands/command_queue.rs +++ b/crates/bevy_ecs/src/system/commands/command_queue.rs @@ -24,7 +24,7 @@ struct CommandMeta { // entities/components/resources, and it's not currently possible to parallelize these // due to mutable [`World`] access, maximizing performance for [`CommandQueue`] is // preferred to simplicity of implementation. -#[derive(Default)] +#[derive(Debug, Default)] pub struct CommandQueue { // This buffer densely stores all queued commands. // From 528f866ed28897eb341ff416bed796256fe0b49e Mon Sep 17 00:00:00 2001 From: Pixelstorm Date: Sun, 21 Jan 2024 16:38:03 +0000 Subject: [PATCH 2/3] Impl debug manually rather than deriving it --- .../src/system/commands/command_queue.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/system/commands/command_queue.rs b/crates/bevy_ecs/src/system/commands/command_queue.rs index 817c580831ce4..e3b3a0c3bdd49 100644 --- a/crates/bevy_ecs/src/system/commands/command_queue.rs +++ b/crates/bevy_ecs/src/system/commands/command_queue.rs @@ -1,4 +1,4 @@ -use std::mem::MaybeUninit; +use std::{fmt::Debug, mem::MaybeUninit}; use bevy_ptr::{OwningPtr, Unaligned}; use bevy_utils::tracing::warn; @@ -24,7 +24,7 @@ struct CommandMeta { // entities/components/resources, and it's not currently possible to parallelize these // due to mutable [`World`] access, maximizing performance for [`CommandQueue`] is // preferred to simplicity of implementation. -#[derive(Debug, Default)] +#[derive(Default)] pub struct CommandQueue { // This buffer densely stores all queued commands. // @@ -34,6 +34,19 @@ pub struct CommandQueue { bytes: Vec>, } +// CommandQueue needs to implement Debug manually, rather than deriving it, because the derived impl just prints +// [core::mem::maybe_uninit::MaybeUninit, core::mem::maybe_uninit::MaybeUninit, ..] for every byte in the vec, +// which gets extremely verbose very quickly, while also providing no useful information. +// It is not possible to soundly print the values of the contained bytes, as some of them may be padding or uninitialized (#4863) +// So instead, the manual impl just prints the length of vec. +impl Debug for CommandQueue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("CommandQueue") + .field("len", &self.bytes.len()) + .finish_non_exhaustive() + } +} + // SAFETY: All commands [`Command`] implement [`Send`] unsafe impl Send for CommandQueue {} From ce115598d4ae29b74039fbe187ffadd19454daab Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Mon, 22 Jan 2024 10:31:41 -0500 Subject: [PATCH 3/3] len -> len_bytes --- crates/bevy_ecs/src/system/commands/command_queue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/system/commands/command_queue.rs b/crates/bevy_ecs/src/system/commands/command_queue.rs index e3b3a0c3bdd49..0e372c6038358 100644 --- a/crates/bevy_ecs/src/system/commands/command_queue.rs +++ b/crates/bevy_ecs/src/system/commands/command_queue.rs @@ -42,7 +42,7 @@ pub struct CommandQueue { impl Debug for CommandQueue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("CommandQueue") - .field("len", &self.bytes.len()) + .field("len_bytes", &self.bytes.len()) .finish_non_exhaustive() } }