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