fix(simulation): address bridge review feedback
Replace .lock().unwrap() with .expect("mutex poisoned") in LocalBridge
for clearer panic messages. Document 16MB MAX_MESSAGE_SIZE rationale
in framing.rs with entity count sizing analysis.
Addresses Hoshe PR review suggestions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,10 @@
|
||||
|
||||
use std::io::{self, Read, Write};
|
||||
|
||||
/// Maximum message size: 16 MB
|
||||
/// Maximum message size: 16 MB.
|
||||
/// Sized for ObserverSnapshot with ~1000 entities (each ~40 bytes serialized),
|
||||
/// plus generous headroom for future field additions. A full-map dump of 10k
|
||||
/// entities would be ~400 KB, well within this limit.
|
||||
const MAX_MESSAGE_SIZE: u32 = 16 * 1024 * 1024;
|
||||
|
||||
/// Write a length-prefixed message to a writer.
|
||||
|
||||
@@ -83,7 +83,7 @@ impl SimBridge for LocalBridge {
|
||||
fn send_snapshot(&self, snapshot: &ObserverSnapshot) -> Result<(), BridgeError> {
|
||||
let payload = rmp_serde::to_vec(snapshot)?;
|
||||
|
||||
let mut writer = self.writer.lock().unwrap();
|
||||
let mut writer = self.writer.lock().expect("writer mutex poisoned");
|
||||
write_framed(writer.get_mut(), &payload)?;
|
||||
|
||||
tracing::trace!("sent snapshot: tick={}", snapshot.tick);
|
||||
@@ -91,7 +91,7 @@ impl SimBridge for LocalBridge {
|
||||
}
|
||||
|
||||
fn receive_inputs(&self) -> Result<Vec<PlayerInput>, BridgeError> {
|
||||
let mut reader = self.reader.lock().unwrap();
|
||||
let mut reader = self.reader.lock().expect("reader mutex poisoned");
|
||||
|
||||
match read_framed(reader.get_mut())? {
|
||||
Some(payload) => {
|
||||
|
||||
Reference in New Issue
Block a user