Fix #2171: crash when opening window