From 12ae54c6059b7ce0d8d89510af45794f62760dfd Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Mon, 10 Jan 2022 16:46:52 -0800 Subject: [PATCH] Add some more explanation to Console::drop --- ctru-rs/src/console.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ctru-rs/src/console.rs b/ctru-rs/src/console.rs index 21d2c66..1a226b7 100644 --- a/ctru-rs/src/console.rs +++ b/ctru-rs/src/console.rs @@ -54,6 +54,11 @@ impl Default for Console { impl Drop for Console { fn drop(&mut self) { unsafe { + // Safety: We are about to deallocate the PrintConsole data pointed + // to by libctru. Without this drop code libctru would have a + // dangling pointer that it writes to on every print. To prevent + // this we replace the console with the default if it was selected. + // Get the current console by replacing it with the default. let default_console = ctru_sys::consoleGetDefault(); let current_console = ctru_sys::consoleSelect(default_console);