Fix a wx segfault bug during MainWindow destruction