I have a window that inherits from DocumentWindow
. How do I indicate to JUCE that it can go ahead and close a window from within the method closeButtonPressed()
?
When I look at the call stack at that point, I’m where you’d expect in the usual JUCE message handling. The stack looks like this:
MyWnd::closeButtonPressed()
juce::DocumentWindow::userTriedToCloseWindow()
juce::ComponentPeer::handleUserClosingWindow()
juce::LinuxComponentPeer::handleClientMessageEvent(XClientMessageEvent&, _XEvent&)
juce::LinuxComponentPeer::handleWindowMessage(_XEvent&)
...
juce::InternalMessageQueue::dispatchNextEvent()
juce::MessageManager::dispatchNextMessageOnSystemQueue(bool)
juce::MessageManager::runDispatchLoop()
If I call something like delete this
(which is what the docs hint is one possibility) wont this cause serious memory problems when the object+method that is running all of a sudden is deleted before the method has finished returning?
Please excuse my English. Let me try and word it differently:
- MyWnd::closeButtonPressed() is running.
- Within that method, I call
delete this
- Memory is reclaimed by the OS (or the C++ runtime) when the window is deleted
- …but MyWnd.closeButtonPressed() hasn’t returned yet! Wouldn’t it now be undefined behaviour since the memory area for MyWnd was released?