[Interest] Debugging a double dealloc

Ben Haller bhaller at mac.com
Thu Sep 24 04:44:31 CEST 2020


> Hi Ben,

Hi Tony,

Lot’s of questions here!  Let’s see:

> There may indeed be an issue with fonts being tied to having at least one window present, which causes you grief when you delete the main window.
> 
> Have you tried the suggestion from your other thread to just hide the main window instead?

  Actually, that is what I tried – that’s the case where the crash occurs.  If I don’t set my main windows to delete on close, then they just close (no delete, just hide), and then the app crashes on quit.  If I set them to delete on close, then the app doesn’t crash on quit, interestingly; but then the global menubar problem I described happens instead.  :-<  So it seems like perhaps whatever font cache exists gets dealloced when the last main window *closes*, not when the last main window *deallocs*; and then when the app quits, the code tries to dealloc it again, and boom.  I’m not certain of those details, but that’s my hypothesis.

> Where is the tick font used?  Does your main menu that you want to persist without any windows use it?

  It’s only used in that one spot that was in the snippet of code I posted – I set it as the font on a painter that I use to draw in the paintGL() method of my widget.  That’s the only spot it’s used.  So it’s not needed when there’s no main window visible, no.  But the second variant of the code just constructs a stack-allocated local QFont and uses that, so the QFont goes out of scope as soon as paintGL() is done, and that still crashes on quit.  So even if the lifetime of the QFont that I’m using is very short (local scope), it’s the lifetime of QApplication’s internal font cache that is the issue, and I have no control over how that is handled.

> Have you tried a cut-down app that creates a plain QMainWindow, a plain main menu, then destroys the main window to see if persisting the main menu is actually doable on Mac?

  No, I haven’t tried constructing a minimal test case.  I’m not super fluent in Qt, so that’s more daunting than it might sound; I’m not really sure what’s essential for a minimal Qt app and what isn’t, etc.  It definitely does seem like this usage pattern, of trying to keep the app running after the last main window closes using a global menubar, has maybe not gotten a lot of testing, since I’ve found two bugs so far and have been unable to get it to work.  It may be that there are unusual things about my app, though; my usage of OpenGL views is probably somewhat unusual, and that’s clearly linked to the crash on quit.

  Sorry if my descriptions of the bugs in these emails have been a bit hard to follow; I was writing the emails as I was figuring things out.  I’ve tried to present all the info more clearly in the two bugs I filed (QTBUG-86874 and QTBUG-86875).  :->

  Thanks for your followup!

Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University



More information about the Interest mailing list