From 368cf8bc0c4e79ef13ce73796f82ac84cddb33be Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Sat, 5 Feb 2022 17:29:19 -0800 Subject: [PATCH] Increase stack size and add more detailed logs The default stack size is super small: 4096 bytes. This was causing the stack to overflow during normal processing. This was also not detected, so it corrupted the heap and led to odd behavior or aborts. See this long comment for more details and explanation: https://github.com/Meziu/ctru-rs/pull/42#issuecomment-1030724973 I bumped the stack size to 2MiB, which is the default for Rust's std threads. I have a few ideas to fix the underlying issues here (add a guard struct like std does for stack overflows, move 3ds-specific stuff like affinity into std but keep the impl in ctru-rs via linker hacks). Also added some more logging. --- ctru-rs/examples/futures-tokio-basic.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ctru-rs/examples/futures-tokio-basic.rs b/ctru-rs/examples/futures-tokio-basic.rs index e8e8775..cf70a85 100644 --- a/ctru-rs/examples/futures-tokio-basic.rs +++ b/ctru-rs/examples/futures-tokio-basic.rs @@ -28,16 +28,21 @@ fn main() { let runtime_thread = ctru::thread::Builder::new() .affinity(1) + .stack_size(0x200000) .spawn(move || { runtime.block_on(async move { + println!("Start of future"); let mut wake_time = tokio::time::Instant::now() + Duration::from_secs(1); + let mut iteration = 0; loop { + println!("Start of loop"); let sleep_future = tokio::time::sleep_until(wake_time); tokio::select! { _ = &mut exit_receiver => break, _ = sleep_future => { - println!("Tick"); + println!("Tick {}", iteration); + iteration += 1; wake_time += Duration::from_secs(1); } }