Save mainwindow state without segfaulting occasionally...