Browse Source

Add back slightly simpler Console::drop

This is needed for soundness. Otherwise libctru will have a dangling
pointer, and will write to it when printing.
pull/17/head
AzureMarker 3 years ago
parent
commit
84ef934223
No known key found for this signature in database
GPG Key ID: 47A133F3BF9D03D3
  1. 19
      ctru-rs/src/console.rs

19
ctru-rs/src/console.rs

@ -50,3 +50,22 @@ impl Default for Console {
Console::init(Screen::Top) Console::init(Screen::Top)
} }
} }
impl Drop for Console {
fn drop(&mut self) {
unsafe {
// Get the current console by replacing it with the default.
let default_console = ctru_sys::consoleGetDefault();
let current_console = ctru_sys::consoleSelect(default_console);
if std::ptr::eq(current_console, &*self.context) {
// Console dropped while selected. We just replaced it with the
// default so there's nothing more to do.
} else {
// Console dropped while a different console was selected. Put back
// the console that was selected.
ctru_sys::consoleSelect(current_console);
}
}
}
}

Loading…
Cancel
Save