|
|
@ -53,22 +53,23 @@ impl Default for Console { |
|
|
|
|
|
|
|
|
|
|
|
impl Drop for Console { |
|
|
|
impl Drop for Console { |
|
|
|
fn drop(&mut self) { |
|
|
|
fn drop(&mut self) { |
|
|
|
|
|
|
|
static mut EMPTY_CONSOLE: PrintConsole = unsafe { const_zero::const_zero!(PrintConsole) }; |
|
|
|
|
|
|
|
|
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
// Safety: We are about to deallocate the PrintConsole data pointed
|
|
|
|
// Safety: We are about to deallocate the PrintConsole data pointed
|
|
|
|
// to by libctru. Without this drop code libctru would have a
|
|
|
|
// to by libctru. Without this drop code libctru would have a
|
|
|
|
// dangling pointer that it writes to on every print. To prevent
|
|
|
|
// dangling pointer that it writes to on every print. To prevent
|
|
|
|
// this we replace the console with the default if it was selected.
|
|
|
|
// this we replace the console with an empty one if it was selected.
|
|
|
|
|
|
|
|
// This is the same state that libctru starts up in, before
|
|
|
|
|
|
|
|
// initializing a console. Writes to the console will not show up on
|
|
|
|
|
|
|
|
// the screen, but it won't crash either.
|
|
|
|
|
|
|
|
|
|
|
|
// Get the current console by replacing it with the default.
|
|
|
|
// Get the current console by replacing it with an empty one.
|
|
|
|
let default_console = ctru_sys::consoleGetDefault(); |
|
|
|
let current_console = ctru_sys::consoleSelect(&mut EMPTY_CONSOLE); |
|
|
|
let current_console = ctru_sys::consoleSelect(default_console); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if std::ptr::eq(current_console, &*self.context) { |
|
|
|
if std::ptr::eq(current_console, &*self.context) { |
|
|
|
// Console dropped while selected. We just replaced it with the
|
|
|
|
// Console dropped while selected. We just replaced it with the
|
|
|
|
// default so make sure it's initialized.
|
|
|
|
// empty console so nothing more to do.
|
|
|
|
if !(*default_console).consoleInitialised { |
|
|
|
|
|
|
|
ctru_sys::consoleInit(Screen::Top.into(), default_console); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Console dropped while a different console was selected. Put back
|
|
|
|
// Console dropped while a different console was selected. Put back
|
|
|
|
// the console that was selected.
|
|
|
|
// the console that was selected.
|
|
|
|