C , 2011-10-13 13:53 -0400, David Lonie rakstīja:
> There does seem to be a new problem that took its place. In the
> attached script, I've added line 36, which will print the name of the
> forcefield that was found. When I run the test script now, I get:
> 
> Forcefield is of type: UFF
> Forcefield is of type: GAFF
> 
> despite using FindForceField("UFF") in each case. So something is
> still not quite there. Any ideas?

Yes, I misunderstood the function of Default() a bit. Turns out that it
is a pointer to an instance of default sub-type for a plugin type (not
to the default instance of a sub-type).

As I understand, plugins do not keep track of their instances. So when
you create new one with MakeNewInstance() the reference to old one is
lost (Doesn't it lead to memory leaks?).

So if we add a static member variable to the OBForceFieldUFF class which
keeps pointers to the live instances, then we can use that in destructor
to reset plugin map pointers to the original instance. Something like in
the attached patch for OBForceFieldUFF.

I'm not sure if this is the best solution, but it seems like something
that is working. Hope it helps.


Reinis
Index: src/forcefields/forcefielduff.cpp
===================================================================
--- src/forcefields/forcefielduff.cpp	(revision 4635)
+++ src/forcefields/forcefielduff.cpp	(working copy)
@@ -563,6 +563,8 @@
     return energy;
   }
 
+  std::vector<OBForceFieldUFF*> OBForceFieldUFF::_instances;
+
   //***********************************************
   //Make a global instance
   OBForceFieldUFF theForceFieldUFF("UFF", true);
@@ -570,6 +572,9 @@
 
   OBForceFieldUFF::~OBForceFieldUFF()
   {
+    Map()[_id] = _instances[0];
+    PluginMap()[TypeID()] = _instances[0];
+    _instances.pop_back();
   }
 
   OBForceFieldUFF &OBForceFieldUFF::operator=(OBForceFieldUFF &src)
Index: src/forcefields/forcefielduff.h
===================================================================
--- src/forcefields/forcefielduff.h	(revision 4635)
+++ src/forcefields/forcefielduff.h	(working copy)
@@ -117,6 +117,8 @@
     std::vector<OBFFVDWCalculationUFF>           _vdwcalculations;
     std::vector<OBFFElectrostaticCalculationUFF> _electrostaticcalculations;
 
+    static std::vector<OBForceFieldUFF*> _instances;
+
   public:
     //! Constructor
     explicit OBForceFieldUFF(const char* ID, bool IsDefault=true) : OBForceField(ID, IsDefault)
@@ -128,6 +130,7 @@
       _pairfreq = 10;
       _cutoff = false;
       _linesearch = LineSearchType::Simple;
+      _instances.push_back(this);
     }
 
     //! Destructor
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel

Reply via email to