Skip to content

Commit 05cd631

Browse files
committed
Test handling broken log pipe better
1 parent 1b5c758 commit 05cd631

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

  • sable_rapier/src/main/rust/rapier/src

sable_rapier/src/main/rust/rapier/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use jni::sys::{jboolean, jdouble, jint, jlong};
1818
use jni::{JNIEnv, JavaVM};
1919
use rapier3d::glamx::{DVec3, Quat};
2020
use std::collections::HashMap;
21+
use std::io::{self, Write};
2122
use std::sync::{Arc, OnceLock, RwLock};
2223

2324
use fern::colors::{Color, ColoredLevelConfig};
@@ -303,6 +304,20 @@ pub fn get_rigid_body<'a>(
303304
&sim.rigid_body_set[*handle]
304305
}
305306

307+
struct LogWriter;
308+
309+
impl Write for LogWriter {
310+
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
311+
let mut stdout = io::stdout().lock();
312+
stdout.write(buf)
313+
}
314+
315+
fn flush(&mut self) -> io::Result<()> {
316+
let mut stdout = io::stdout().lock();
317+
stdout.flush()
318+
}
319+
}
320+
306321
#[unsafe(no_mangle)]
307322
pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_initialize<'local>(
308323
env: JNIEnv<'local>,
@@ -330,7 +345,7 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_ini
330345
})
331346
.level(log::LevelFilter::Info)
332347
.level_for("jni", log::LevelFilter::Error)
333-
.chain(std::io::stdout())
348+
.chain(fern::Output::writer(Box::new(LogWriter), "\n"))
334349
.apply();
335350

336351
RwLock::new(PhysicsState {

0 commit comments

Comments
 (0)