Skip to content

Commit

Permalink
MacOSX: Keep DoDragDrop() from re-entering to enable a proper working…
Browse files Browse the repository at this point in the history
… CEF.

DoDragDrop() may make CEF cease to work.
One way to reproduce the problem:
Do drag-n-drop repeatly, that is, start drag immediately after one drop,
then there're chances we can see large amount of DoDragDrop() in the callstack
of the UI-thread. And finally leads to stack overflow.
Messages processed by CEF are handled when wxEVT_IDLE is triggered.
The basic loop are:
-> Step1, cocoa call OSXDefaultModeObserverCallBack(in src/osx/core/evtloop_cf.cpp)
-> Step2, wxEVT_IDLE is triggered.
-> Step3, wxWebViewChroium::OnIdle() takes the cake.
-> Step4, CefDoMessageLoopWork() do the jobs for CEF.

If DoDragDrop() is invoked during CefDoMessageLoopWork(), and together there comes a recursive call to it,
then the previous DoDragDrop() can't return anymore, and will, in turn, prevent CefDoMessageLoopWork()
from returning to the caller. And finally overflow the stack.

And now we add the global dnd flag to stay away from this kind of tragic.
  • Loading branch information
徐扬斌 committed Apr 29, 2024
1 parent 6f4f244 commit e998db7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/osx/cocoa/dnd.mm
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,16 @@ - (nullable id)pasteboardPropertyListForType:(nonnull NSPasteboardType)type
wxDragResult wxDropSource::DoDragDrop(int flags)
{
wxASSERT_MSG( m_data, wxT("Drop source: no data") );

static bool g_in_dnd = false;

wxDragResult result = wxDragNone;
if ((m_data == nullptr) || (m_data->GetFormatCount() == 0))
return result;


if (g_in_dnd)
return wxDragNone;

g_in_dnd = true;
NSView* view = m_window->GetPeer()->GetWXWidget();
if (view)
{
Expand Down Expand Up @@ -554,8 +559,8 @@ - (nullable id)pasteboardPropertyListForType:(nonnull NSPasteboardType)type

gCurrentSource = nullptr;
}


g_in_dnd = false;
return result;
}

Expand Down

0 comments on commit e998db7

Please sign in to comment.