常见坑与报错原文排查指南
主线位置:实战排错手册。本页按报错原文列出使用
copper-rs时最容易踩到的 4 个坑及其源码级根因。
flowchart TB err["遇到编译或运行报错"] --> e1["编译期: Cannot find configuration file"] err --> e2["编译期: the trait ValueDecode is not implemented"] err --> e3["运行期: Section is full / Out of space in section"] err --> e4["运行期: rtsan Realtime violation detected"]
坑 1:编译期报错 Cannot find configuration file
- 触发场景:在结构体上写
#[copper_runtime(config = "copperconfig.ron")]时宏报错找不到配置文件。 - 源码根因:
core/cu29_derive/src/utils.rs是相对于当前子 crate 的CARGO_MANIFEST_DIR(即包含Cargo.toml的目录)拼接相对路径的,而不是工作区根目录! - 解法:确保
"copperconfig.ron"放在当前二进制 crate 的Cargo.toml同级目录下,且修改.ron文件后若未触发增量重编,可在build.rs中调用println!("cargo:rerun-if-changed=copperconfig.ron");。
坑 2:自定义 Payload 报错 the trait bincode::de::Decode<()> is not implemented 或缺少 Reflect
- 触发场景:自己定义了一个消息结构体
pub struct MyCmd { pub v: f32 }放进.ron的cnx中,展开gen_cumsgs!时报 Trait 未实现。 - 源码根因:
CuMsgPayload要求载荷类型同时实现Default + Debug + Clone + Encode + Decode<()> + Serialize + Deserialize(开启reflect或self-describing-logs时还需对应的反射派生)。 - 解法:自定义消息结构体一律派生完整套装,并确认
Cargo.toml中将bincode指向cu-bincode:use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize}; #[derive(Default, Debug, Clone, PartialEq, Encode, Decode, Serialize, Deserialize)] pub struct MyCmd { pub v: f32, }
坑 3:运行期报错单帧 CopperList 超过 section_size_mib
- 触发场景:在
CopperList中直接塞入未压缩的高清图像或超大点云数组,运行期UnifiedLogger报 Section 空间不足。 - 源码根因:在
core/cu29_unifiedlog/src/memmap.rs中,单个SectionStorage的容量由.ron中的section_size_mib决定,若单轮CopperList编码后的字节数接近或超过单个 Section 容量,分配器无法容纳。 - 解法:在
.ron的logging: (slab_size_mib: 512, section_size_mib: 64)中调大section_size_mib与slab_size_mib,或对不需要全量录制的中间大图像在.ron节点上设置logging: (enabled: false)。
坑 4:开启 rtsan 或 memory_monitoring 后发现 process() 中存在隐式堆分配
- 触发场景:在
process()中调用了format!(...)或vec![...],被CountingAlloc或rtsan抓出实时违规。 - 解法:将状态字符串改为写入
output.metadata.set_status("OK")(底层为 24 字节栈内联CuCompactString),将动态Vec改为#[derive(Soa)]定长结构体或启动期预分配的CuHostMemoryPool。
❗IMPORTANT
动脑筋:如果只想跳过某一个高带宽视觉节点的 CopperList 录制以节省磁盘空间,同时保留 IMU 和控制节点的录制,需要改 Rust 代码吗?
动脑筋答案
完全不需要改 Rust 代码!直接在 copperconfig.ron 对应视觉节点的配置项里加上 logging: (enabled: false),cu29-derive 在生成 CuStampedDataSet 的序列化实现时就会自动跳过该槽位。
小结
- 掌握
CARGO_MANIFEST_DIR相对路径、CuMsgPayload派生要求与logging容量配置,即可避开 95% 的常见报错。
💬 关联讨论
加载中...

