Commit c775bd19 authored by Peter Eastman's avatar Peter Eastman
Browse files

Fixed error that required Context and Integrator to be deleted in a particular order

parent cd6af26e
...@@ -54,6 +54,7 @@ class ContextImpl; ...@@ -54,6 +54,7 @@ class ContextImpl;
class OPENMM_EXPORT Integrator { class OPENMM_EXPORT Integrator {
public: public:
virtual ~Integrator() { virtual ~Integrator() {
cleanup();
} }
/** /**
* Get the size of each time step, in picoseconds. If this integrator uses variable time steps, * Get the size of each time step, in picoseconds. If this integrator uses variable time steps,
...@@ -92,6 +93,7 @@ public: ...@@ -92,6 +93,7 @@ public:
*/ */
virtual void step(int steps) = 0; virtual void step(int steps) = 0;
protected: protected:
friend class Context;
friend class ContextImpl; friend class ContextImpl;
/** /**
* This will be called by the Context when it is created. It informs the Integrator * This will be called by the Context when it is created. It informs the Integrator
...@@ -103,7 +105,8 @@ protected: ...@@ -103,7 +105,8 @@ protected:
* This will be called by the Context when it is destroyed to let the Integrator do any necessary * This will be called by the Context when it is destroyed to let the Integrator do any necessary
* cleanup. It will also get called again if the application calls reinitialize() on the Context. * cleanup. It will also get called again if the application calls reinitialize() on the Context.
*/ */
virtual void cleanup() = 0; virtual void cleanup() {
};
/** /**
* Get the names of all Kernels used by this Integrator. * Get the names of all Kernels used by this Integrator.
*/ */
......
...@@ -216,6 +216,7 @@ void Context::reinitialize() { ...@@ -216,6 +216,7 @@ void Context::reinitialize() {
System& system = impl->getSystem(); System& system = impl->getSystem();
Integrator& integrator = impl->getIntegrator(); Integrator& integrator = impl->getIntegrator();
Platform& platform = impl->getPlatform(); Platform& platform = impl->getPlatform();
integrator.cleanup();
delete impl; delete impl;
impl = new ContextImpl(*this, system, integrator, &platform, properties); impl = new ContextImpl(*this, system, integrator, &platform, properties);
} }
......
...@@ -122,7 +122,6 @@ ContextImpl::~ContextImpl() { ...@@ -122,7 +122,6 @@ ContextImpl::~ContextImpl() {
updateStateDataKernel = Kernel(); updateStateDataKernel = Kernel();
applyConstraintsKernel = Kernel(); applyConstraintsKernel = Kernel();
virtualSitesKernel = Kernel(); virtualSitesKernel = Kernel();
integrator.cleanup();
platform->contextDestroyed(*this); platform->contextDestroyed(*this);
} }
......
...@@ -255,6 +255,7 @@ CudaContext::~CudaContext() { ...@@ -255,6 +255,7 @@ CudaContext::~CudaContext() {
string errorMessage = "Error deleting Context"; string errorMessage = "Error deleting Context";
if (contextIsValid) if (contextIsValid)
CHECK_RESULT(cuCtxDestroy(context)); CHECK_RESULT(cuCtxDestroy(context));
contextIsValid = false;
} }
void CudaContext::initialize() { void CudaContext::initialize() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment