Skip to content

Commit

Permalink
Merge pull request #1933 from ghutchis/more-forcefield-care
Browse files Browse the repository at this point in the history
Added more defensive programming in the forcefield code
  • Loading branch information
ghutchis authored Jan 11, 2025
2 parents 4421877 + 5959265 commit cd10b18
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 3 additions & 5 deletions avogadro/qtplugins/forcefield/forcefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,11 @@ void Forcefield::setupMethod()
m_methodName = recommendedForceField();
}

if (m_method == nullptr) {
// we have to create the calculator
m_method = Calc::EnergyManager::instance().model(m_methodName);
} else if (m_method->identifier() != m_methodName) {
if (m_method != nullptr) {
delete m_method; // delete the previous one
m_method = Calc::EnergyManager::instance().model(m_methodName);
}
m_method = Calc::EnergyManager::instance().model(m_methodName);

if (m_method != nullptr)
m_method->setMolecule(m_molecule);
}
Expand Down
4 changes: 2 additions & 2 deletions avogadro/qtplugins/forcefield/obenergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class OBEnergy::Private

~Private()
{
delete m_obmol;
delete m_forceField;
if (m_obmol != nullptr)
delete m_obmol;
}
};

Expand Down
3 changes: 2 additions & 1 deletion avogadro/qtplugins/forcefield/obmmenergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ OBMMEnergy::OBMMEnergy(const std::string& method)
OBMMEnergy::~OBMMEnergy()
{
delete m_inputFormat;
delete m_process;
if (m_process != nullptr)
delete m_process;
}

bool OBMMEnergy::acceptsRadicals() const
Expand Down

0 comments on commit cd10b18

Please sign in to comment.