Hang on showing a contextual menu



  • I’m experiencing hang on showing a contextual menu in a window with a QWebEngineView.

    void WebWindow::showContextMenu(QPoint )
    {
    	//QMenu& menu=*this->oWebView->page()->createStandardContextMenu();
    	
    	QMenu menu;
    	…	add some actions
    
    	 action=menu.exec(QCursor::pos());	// never return after a click on a menu item
    

    This issue accurs with all Qt version i used, in Qt 5.5 accurs frequently, in Qt 5.6 rarely, in Qt 5.7 crash on createStandardContextMenu() :)
    With 5.7.1 it’s occurred very rarely.
    On quitting or closing the window the app crash:

    Crashed Thread:  0  CrBrowserMain  Dispatch queue: com.apple.main-thread
    
    Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000010
    
    Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
    0   org.qt-project.QtWebEngineWidgets	0x000000010a88a42b QWebEnginePagePrivate::contextMenuRequested(QtWebEngineCore::WebEngineContextMenuData const&) + 347
    1   ???                           	0x000000010a91b7a5 0 + 4472289189
    2   ???                           	0x000000010c39e796 0 + 4500088726
    3   ???                           	0x000000010c1a0890 0 + 4498000016
    4   ???                           	0x000000010c19e3da 0 + 4497990618
    5   ???                           	0x000000010c2df159 0 + 4499304793
    6   ???                           	0x000000010b42eb18 0 + 4483902232
    7   ???                           	0x000000010b4ba80b 0 + 4484474891
    8   ???                           	0x000000010b4d68a2 0 + 4484589730
    9   ???                           	0x000000010b4d6de7 0 + 4484591079
    10  ???                           	0x000000010a8ddb47 0 + 4472036167
    11  org.qt-project.QtCore         	0x000000010f7469b9 QObject::event(QEvent*) + 857
    12  org.qt-project.QtWidgets      	0x0000000110189a4d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269
    13  org.qt-project.QtWidgets      	0x000000011018c392 QApplication::notify(QObject*, QEvent*) + 5906
    14  org.qt-project.QtCore         	0x000000010f71c5c4 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 164
    15  org.qt-project.QtCore         	0x000000010f71d1f8 QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) + 600
    16  libqcocoa.dylib               	0x000000011c826f4e QCocoaEventDispatcherPrivate::processPostedEvents() + 190
    17  libqcocoa.dylib               	0x000000011c827811 QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void*) + 33
    18  com.apple.CoreFoundation      	0x00000001109485b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    19  com.apple.CoreFoundation      	0x0000000110939d29 __CFRunLoopDoSources0 + 441
    20  com.apple.CoreFoundation      	0x00000001109393ef __CFRunLoopRun + 831
    

    Unfortunately i’m enable to find a way to reproduce the hang, seems to occur at random.
    Sometimes, i’m able to unlock the situation by clicking on the url or search field on the toolbar of the window.

    QCreator 4.2, Qt 5.7.1, OSX 10.9.5
    Thanks


  • Moderators

    @mpergand There's really no way for us to help you without seeing at least the full code for the context menu function.

    This is definitely a tough problem as it probably has more to do with what you're doing with the web view than the actual context menu itself.

    That being said I haven't had any trouble with QWebView or context menus in my apps that use them. However my last app that used a web view was back in Qt 5.3 or maybe earlier so it could be a new bug or something.

    Hard to tell and the backtrace doesn't show us much, contextually, as to what might be going on.



  • Did you try to build your project in release mode ? or other version like Qt 5.8 beta ? In the earlier time, i have a problem with context menu built in debug mode, when i righ-click to a link it sometime crash my application. Then i built my project in release mode, it work again. (Qt 5.8 beta)



  • Thanks for your replies,

    I am doing basic things in the context menu:

    void WebWindow::showContextMenu(QPoint )
    {
       QMenu menu;
        QAction* action;
        QUrl url=aLinkUrl;
        QString ext=FilePath(url.fileName()).extension();
    
        QMimeDatabase mimeDB;
        QMimeType mime = mimeDB.mimeTypeForFile(url.fileName());
        QString type=mime.name().section('/',0,0);
    
        if(!url.isEmpty())
            {
            action=menu.addAction(tr("Open Link in New Window"));
            action->setObjectName(Menu_OpenNewWindow);
    
            action=menu.addAction(tr("Copy Link"));
            action->setObjectName(Menu_CopyLink);
            }
        else
            {
            action=menu.addAction(tr("Add to Bookmarks"));
            action->setObjectName(Menu_AddBookmark);
            if(bLoading)
                action->setEnabled(false);
            }
    
        action=menu.addAction(tr("Reload"));
        action->setObjectName(Menu_Reload);
        action=menu.exec(QCursor::pos());
    

    This app is a portage from a Webkit version, and this issue appears as soon as I'm using the WebEbgine ( Qt 5.5)

    In earlier versions on Qt (5.5 5.6), the crash logs were different:

    Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
    0   org.qt-project.QtCore         	0x000000010dea2af8 QObject::blockSignals(bool) + 8
    1   org.qt-project.QtWidgets      	0x000000010532f84c QMenuPrivate::hideMenu(QMenu*) + 508
    2   org.qt-project.QtWidgets      	0x000000010532f543 QMenuPrivate::hideUpToMenuBar() + 115
    3   org.qt-project.QtWidgets      	0x000000010533081a QMenuPrivate::activateAction(QAction*, QAction::ActionEvent, bool) + 346
    4   org.qt-project.QtWidgets      	0x00000001051fd0b8 QWidget::event(QEvent*) + 1656
    5   org.qt-project.QtWidgets      	0x0000000105336fb1 QMenu::event(QEvent*) + 1105
    
    Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
    0   org.qt-project.QtWebEngineWidgets	0x000000010e487066 QWebEnginePagePrivate::contextMenuRequested(QtWebEngineCore::WebEngineContextMenuData const&) + 790
    1   org.qt-project.Qt.QtWebEngineCore	0x000000010ebe5975 QtWebEngineCore::WebContentsViewQt::ShowContextMenu(content::RenderFrameHost*, content::ContextMenuParams const&) + 1045
    2   org.qt-project.Qt.QtWebEngineCore	0x0000000110463a16 non-virtual thunk to content::WebContentsImpl::ShowContextMenu(content::RenderFrameHost*, content::ContextMenuParams const&) + 86
    3   org.qt-project.Qt.QtWebEngineCore	0x000000011028876b content::RenderFrameHostImpl::OnMessageReceived(IPC::Message const&) + 2763
    4   org.qt-project.Qt.QtWebEngineCore	0x00000001103b1279 content::RenderProcessHostImpl::OnMessageReceived(IPC::Message const&) + 761
    5   org.qt-project.Qt.QtWebEngineCore	0x000000010f45c2a8 IPC::ChannelProxy::Context::OnDispatchMessage(IPC::Message const&) + 120
    6   org.qt-project.Qt.QtWebEngineCore	0x000000010f4e6f9f base::debug::TaskAnnotator::RunTask(char const*, char const*, base::PendingTask const&) + 239
    7   org.qt-project.Qt.QtWebEngineCore	0x000000010f5021ca base::MessageLoop::RunTask(base::PendingTask const&) + 378
    8   org.qt-project.Qt.QtWebEngineCore	0x000000010f502597 base::MessageLoop::DoWork() + 439
    9   org.qt-project.Qt.QtWebEngineCore	0x000000010ebb5907 QtWebEngineCore::(anonymous namespace)::MessagePumpForUIQt::customEvent(QEvent*) + 23
    10  org.qt-project.QtCore         	0x00000001171bd999 QObject::event(QEvent*) + 857
    

    This issue doesn't seem to occur on Linux ( I'm on OSX)

    @Bui Trung
    No I didn't try on release mode since this app is still in progress. Maybe worth a try ...


  • Moderators

    @mpergand Hmm, I'm pretty much at a loss on this one. I have no suggestions on where to look.

    Your menu code is simple and correct.

    Can you try to find a simple example where it can be reproduced? Something we can easily duplicate on our own systems? It's possible (probable in fact) that it exists somewhere in your other web page code handling, but there's just no way for me to guess at where with the info I have currently.



  • It's very hard to reproduce.
    It is maybe related some how with the search field in the toobar.
    Yesterday, i was able to reproduce the hang twice after using the search field, but i can't anymore !
    After pressing ENTER in the search field, the Google page loads, everything seems ok, i can click on the links, but if i right-click and choose "Open in new window" the hang arises, and suprisingly, if i click on the search field, the menu.exec() method returns and the new window opens.
    From the begining i know there is a issue with search field and i try this code:

    void WebBrowserToolBar::proceedSearch(const QString& text)
    {
    	if(text.isEmpty()) return;
    
    InvokeLaterWithArg(_proceedSearch,QString,text);
    }
    
    void WebBrowserToolBar::_proceedSearch(const QString &text)
    {
        QByteArray query=QUrl::toPercentEncoding(text);
        QUrl url("http://google.fr/search?q="+query);
    
        oWebWindow->load(url);
    }
    

    Since it seems related to the eventloop, i try to execute the slot method through the eventloop in Qt::QueuedConnection mode (InvokeLater is a macro).
    I believed it solves the issue but in fact not at all.

    The crash logs show the issue is related with QtWebEngineCore::WebEngineContextMenuData
    Is the data may be corrupted by some way ?


  • Moderators

    @mpergand The data could be corrupted if you had a bad pointer or something somewhere. That would cause a crash.

    I wish I had more to help you, but this project sounds big enough that it would take some real debugging effort to figure out an intermittent hang/crash in a 3rd party webkit, lol. Since I don't have code or the time to dig into that I just don't have much to offer.

    Maybe start with a smaller application that does similar things (a test of app of some kind) and see if you can reproduce the break. Then maybe slowly introduce sections of your real app until you get a break? That's a trick I use when i've exhausted all my other debugging skills. I rarely get these kinds of bugs any more after 20+ years of coding though. :)



  • Thanks for your advice

    The fact that sometimes i can unblock by clicking in the search field or on another window or putting the app in the dock, leading me to think there's something wrong with the eventloop.
    All the more so as i'm having experienced similar locking in early version of QtCreator on OSX ( the editor panels don't response to mouse click or keyboard stroke)

    I'm going to try if i can reproduce this issue with the DemoBrowser
    To be continued ...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.