Daniel Reetz, the founder of the DIY Book Scanner community, has recently started making videos of prototyping and shop tips. If you are tinkering with a book scanner (or any other project) in your home shop, these tips will come in handy. https://www.youtube.com/channel/UCn0gq8 ... g_8K1nfInQ

Mac problem - contextual menus cause crash

Scan Tailor specific announcements, releases, workflows, tips, etc. NO FEATURE REQUESTS IN THIS FORUM, please.
User avatar
n9yty
Posts: 72
Joined: 25 Jul 2010, 22:13

Re: Mac problem - contextual menus cause crash

Post by n9yty » 03 Nov 2010, 22:36

Tulon wrote:The log you produced is quite interesting. aboutToHide() was fired first and issued deleteLater() on ZoneContextMenuInteraction. 125 ms after that, triggered() was fired. Fine - could be some animation or something. 746 ms later, ZoneContextMenuInteraction finally gets destroyed. What took it so long? This should have happened right at the next main loop iteration, and we saw almost 500 of them pass by.
Interesting indeed, I don't think I have an answer at this point... :)
Tulon wrote:Anyway, I believe that if you delay menuAboutToHide() by say 200 ms, that will solve the problem. Performance shouldn't be an issue, as I suspect that 125 ms delay was done the very same way you are going to delay menuAboutToHide(). If so, no matter the performance, those will be fired in the correct order.
In fact, looking at qmenu.cpp we see:

Code: Select all

#if defined(Q_WS_MAC)
static const qreal MenuFadeTimeInSec = 0.150;
#endif
 .
 .
 .
#if defined(Q_WS_MAC)
        if (fadeMenus) {
            QEventLoop eventLoop;
            QTimer::singleShot(int(MenuFadeTimeInSec * 1000), &eventLoop, SLOT(quit()));
            QMacWindowFader::currentFader()->performFade();
            eventLoop.exec();
        }
#endif
 .
 .
 .
#if defined(Q_WS_MAC)
        if (justRegister) {
            QMacWindowFader::currentFader()->setFadeDuration(MenuFadeTimeInSec);
            QMacWindowFader::currentFader()->registerWindowToFade(menu);
        } else {
            macWindowFade(qt_mac_window_for(menu), MenuFadeTimeInSec);
        }
This would be roughly the amount of time we are looking for, isn't it? So maybe we just mimic that. There still is the odd case of not being able to re-open a menu very quickly in succession, but that is far better to live with than the custom QMenu subclassing stuff.

So, in ZoneContextMenuInteraction.h:

Code: Select all

#ifdef Q_WS_MAC
	int m_extraDelaysDone;
#endif
In ZoneContextMenuInteraction.cpp - in the constructor:

Code: Select all

#ifdef Q_WS_MAC
	m_extraDelaysDone = 0;
#endif
In ZoneContextMenuInteraction.cpp - at the top of menuAboutToHide():

Code: Select all

#ifdef Q_WS_MAC
	if (m_extraDelaysDone++ < 1) {
	  QTimer::singleShot(200, this, SLOT(menuAboutToHide()));
	  return;
	}
#endif
I can't seem to crash it with those parameters in place.

Post Reply