Skip to content

Commit

Permalink
Merge pull request #1521 from ghutchis/fix-copy-crash
Browse files Browse the repository at this point in the history
Fix crash with "copy as" and an empty molecule
  • Loading branch information
ghutchis authored Dec 11, 2023
2 parents ae3c873 + 43b8691 commit bc85c78
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions avogadro/qtplugins/copypaste/copypaste.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@

#include <QtCore/QMimeData>

#include <QtGui/QClipboard>
#include <QAction>
#include <QtGui/QClipboard>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMessageBox>


#include <string>
#include <vector>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bc85c78

Please sign in to comment.