From 43b86915735abcbcf95d82b06e6787e5e0e68c68 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Mon, 11 Dec 2023 11:29:21 -0500 Subject: [PATCH] Fix crash with "copy as" and an empty molecule https://discuss.avogadro.cc/t/bug-in-copy-as-in-menu/5096 Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/copypaste/copypaste.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/avogadro/qtplugins/copypaste/copypaste.cpp b/avogadro/qtplugins/copypaste/copypaste.cpp index 379105a587..6b17ff1adc 100644 --- a/avogadro/qtplugins/copypaste/copypaste.cpp +++ b/avogadro/qtplugins/copypaste/copypaste.cpp @@ -13,12 +13,11 @@ #include -#include #include +#include #include #include - #include #include @@ -113,7 +112,8 @@ void CopyPaste::copyInChI() bool CopyPaste::copy(Io::FileFormat* format) { - if (!m_molecule) + if (m_molecule == nullptr || m_molecule->atomCount() == 0 || + format == nullptr) return false; std::string output; @@ -197,6 +197,9 @@ void CopyPaste::cut() void CopyPaste::clear() { + if (m_molecule == nullptr || m_molecule->atomCount() == 0) + return; + if (m_molecule->isSelectionEmpty()) m_molecule->undoMolecule()->clearAtoms(); else {