Main window X active during modal dilaog

I have a main window which can spawn a file chooser and a modal dialogue. I am using launchOptions.runModal() for the dialogue (despite the warning because i don’t know how to get the modal effect otherwise). Everything works except that, for the dialogue only (so not the file chooser), the red X button on the main window is active even when the modal dialogue is displayed (it goes red when you hover over it) and clicking it will quit the program. This is OK except that it would be good if file choosers and modal dialogues would agree on whether the main window X button should be active or not. Also, for the dialogue when the main window X is clicked, there is a jassert trap in ~Desktop indicating a memory leak. Any help or advice would be much appreciated. Thanks.