Can you post some code?

If main window close suddenly, maybe it's a bug in your code, lost pointers..