vcl/source/app/dndhelp.cxx | 18 +++++++++--------- vcl/source/window/mouse.cxx | 14 +++++++++++--- 2 files changed, 20 insertions(+), 12 deletions(-)
New commits: commit 3a683edd9c77e20255357879fc70ce49c9217fa8 Author: Jan-Marek Glogowski <glo...@fbihome.de> AuthorDate: Sat Jan 8 21:29:03 2022 +0100 Commit: Jan-Marek Glogowski <glo...@fbihome.de> CommitDate: Sun Jan 9 00:46:03 2022 +0100 Catch exception if failing to set the drag source ... or the drop target. This is the "don't trust the comment or lose a day debugging WASM AKA don't switch of your brain" commit. The comment was "createInstance can throw any exception", so - no more createInstance, no more exception! Nope, you're WRONG! While the uno::Reference<...>::set(..., UNO_QUERY) might itself not throw an exception, something else from the CreateDragSource or CreateDropTarget call could. The symptom was a caught exception when loading the initial Writer document in SynchronousDispatch::dispatch. While at it, also apply the clean-ups suggested by Mike Kaganski in a comment to the original patch after the merge. Regression from commit 031576105c21b2e0c2585a1236092487d5d193e2 ("VCL move platform code from mouse.cxx into plugins"). Change-Id: If80a90a9a6c070d912584f85b9fd10382b98e29c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128175 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de> diff --git a/vcl/source/app/dndhelp.cxx b/vcl/source/app/dndhelp.cxx index d4d6ea059f06..bf0e897dfc7f 100644 --- a/vcl/source/app/dndhelp.cxx +++ b/vcl/source/app/dndhelp.cxx @@ -143,25 +143,25 @@ void vcl::unohelper::DragAndDropWrapper::dropActionChanged( const css::datatrans } css::uno::Reference<css::uno::XInterface> -vcl::OleDnDHelper(const css::uno::Reference<css::lang::XInitialization>& pDnD, const sal_IntPtr pWin, DragOrDrop eDoD) +vcl::OleDnDHelper(const css::uno::Reference<css::lang::XInitialization>& xDnD, const sal_IntPtr pWin, DragOrDrop eDoD) { - if (pWin && pDnD) + if (pWin && xDnD) { if (eDoD == vcl::DragOrDrop::Drag) - pDnD->initialize({ uno::Any(), uno::Any(static_cast<sal_uInt64>(pWin)) }); + xDnD->initialize({ uno::Any(), uno::Any(static_cast<sal_uInt64>(pWin)) }); else - pDnD->initialize({ uno::Any(static_cast<sal_uInt64>(pWin)), uno::Any() }); + xDnD->initialize({ uno::Any(static_cast<sal_uInt64>(pWin)), uno::Any() }); } - return css::uno::Reference<css::uno::XInterface>(pDnD); + return xDnD; } css::uno::Reference<css::uno::XInterface> -vcl::X11DnDHelper(const css::uno::Reference<css::lang::XInitialization>& pDnD, const sal_IntPtr pWin) +vcl::X11DnDHelper(const css::uno::Reference<css::lang::XInitialization>& xDnD, const sal_IntPtr pWin) { - if (pWin && pDnD) - pDnD->initialize({ uno::Any(Application::GetDisplayConnection()), + if (pWin && xDnD) + xDnD->initialize({ uno::Any(Application::GetDisplayConnection()), uno::Any(static_cast<sal_uInt64>(pWin)) }); - return css::uno::Reference<css::uno::XInterface>(pDnD); + return xDnD; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/mouse.cxx b/vcl/source/window/mouse.cxx index a25e226ed9fb..02f6c8a484b1 100644 --- a/vcl/source/window/mouse.cxx +++ b/vcl/source/window/mouse.cxx @@ -732,9 +732,17 @@ Reference< css::datatransfer::dnd::XDragSource > Window::GetDragSource() if (mpWindowImpl->mpFrameData->mxDragSource.is()) return mpWindowImpl->mpFrameData->mxDragSource; - SalInstance* pInst = ImplGetSVData()->mpDefInst; - mpWindowImpl->mpFrameData->mxDragSource.set(pInst->CreateDragSource(pEnvData), UNO_QUERY); - mpWindowImpl->mpFrameData->mxDropTarget.set(pInst->CreateDropTarget(pEnvData), UNO_QUERY); + try + { + SalInstance* pInst = ImplGetSVData()->mpDefInst; + mpWindowImpl->mpFrameData->mxDragSource.set(pInst->CreateDragSource(pEnvData), UNO_QUERY); + mpWindowImpl->mpFrameData->mxDropTarget.set(pInst->CreateDropTarget(pEnvData), UNO_QUERY); + } + catch (const Exception&) + { + mpWindowImpl->mpFrameData->mxDropTarget.clear(); + mpWindowImpl->mpFrameData->mxDragSource.clear(); + } return mpWindowImpl->mpFrameData->mxDragSource; #else return Reference< css::datatransfer::dnd::XDragSource > ();