Skip to content

Commit 41a1e0c

Browse files
徐扬斌coremail-cyt
authored andcommitted
MacOSX: Keep DoDragDrop() from re-entering to enable a proper working 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.
1 parent 3021cbc commit 41a1e0c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/osx/cocoa/dnd.mm

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,16 @@ - (nullable id)pasteboardPropertyListForType:(nonnull NSPasteboardType)type
486486
wxDragResult wxDropSource::DoDragDrop(int flags)
487487
{
488488
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
489-
489+
static bool g_in_dnd = false;
490+
490491
wxDragResult result = wxDragNone;
491492
if ((m_data == NULL) || (m_data->GetFormatCount() == 0))
492493
return result;
493-
494+
495+
if (g_in_dnd)
496+
return wxDragNone;
497+
498+
g_in_dnd = true;
494499
NSView* view = m_window->GetPeer()->GetWXWidget();
495500
if (view)
496501
{
@@ -555,8 +560,8 @@ - (nullable id)pasteboardPropertyListForType:(nonnull NSPasteboardType)type
555560

556561
gCurrentSource = NULL;
557562
}
558-
559-
563+
564+
g_in_dnd = false;
560565
return result;
561566
}
562567

0 commit comments

Comments
 (0)