Fix a segfault error when switching to another window with dialog opened.