On Wed, Oct 12, 2011 at 6:39 PM, My Th <rei4...@gmail.com> wrote:
> T , 2011-10-12 17:17 -0400, David Lonie rakstīja:
>> On Wed, Oct 12, 2011 at 4:53 PM, My Th <rei4...@gmail.com> wrote:
>> >
>> > The reason it breaks on making second instance is that you invalidate
>> > plugin map pointers by deleting the instance. Those pointers are set by
>> > the constructor to point to the new instance, but the destructor doesn't
>> > set them back to the default global instance for the plugin.
>> >
>> > Forcfield destructor should do this:
>> >
>> > OBForceFieldUFF::~OBForceFieldUFF() {
>> >  if (this != Default()) {
>> >    Map()[_id] = Default();
>> >    PluginMap()[TypeID()] = Default();
>> >  }
>> > }
>> >
>> > With this for me your test program runs without crashing.
>>
>> Thanks! I can confirm that this fixes the problem.

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?

Thanks,

Dave
#include <openbabel/forcefield.h>
#include <openbabel/obconversion.h>

class MyClass
{
public:
  MyClass() : m_ff(NULL) {}
  ~MyClass() {delete m_ff; m_ff = NULL;}
  bool setupForceField();
protected:
  OpenBabel::OBForceField *m_ff;
};


bool MyClass::setupForceField()
{
  // already setup!
  if (m_ff != NULL) {
    return true;
  }

  // Initialize forcefield
  // An OBConverison object must be instantiated before the
  // FindForceField call will work.
  OpenBabel::OBConversion conv;
  OpenBabel::OBForceField *static_ff =
      OpenBabel::OBForceField::FindForceField("UFF");
  if (!static_ff) {
    return false;
  }
  OpenBabel::OBForceField *ff = static_ff->MakeNewInstance();
  if (!ff) {
    return false;
  }

  std::cout << "Forcefield is of type: " << ff->GetID() << std::endl;
  m_ff = ff;
  return true;
}

int main()
{
  MyClass *foo, *bar;

  foo = new MyClass();
  foo->setupForceField();
  delete foo;
  foo = NULL;

  bar = new MyClass();
  bar->setupForceField();
  delete bar;
  bar = NULL;

  return 0;
}
------------------------------------------------------------------------------
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