Hi list,

I've written a routine that makes a copy of the UFF forcefield with
MakeNewInstance() and caches it in a member variable of the my class.
The function's definition is:

  bool MyClass::setupForcefield()
  {
    QMutexLocker locker (this->m_ffMutex);

    // 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; Q_UNUSED(conv);
    OpenBabel::OBForceField *static_ff =
        OpenBabel::OBForceField::FindForceField("UFF");
    if (!static_ff) {
      qWarning() << "Cannot locate UFF forcefield. Only the input conformer"
                    " will be used.";
      return false;
    }
    OpenBabel::OBForceField *ff = static_ff->MakeNewInstance();
    if (!ff) {
      qWarning() << "Cannot make new UFF forcefield. Only the input conformer"
                    " will be used.";
      return false;
    }
    ff->SetLogFile(&std::cout);
    ff->SetLogLevel(OBFF_LOGLVL_NONE);

    m_ff = ff;
    return true;
  }

This works perfectly the first time it is used -- the forcefield is
cloned and stored, and is used to successfully generate some
conformers for my molecule. However, creating a new instance of
MyClass and calling this function results in a segfault on the call to
MakeNewInstance. The backtrace is rather unhelpful; the top two frames
after the segfault show the MakeNewInstance line, and then a crash in
libc.

On a hunch, I removed the lines that delete the m_ff object from
MyClass's destructor. When I do this, my test script no longer crashes
when run in the debugger. However, if I run it outside of gdb, it
still segfaults. The only difference that I can imagine is that
execution is slowed in the debugger, which makes me think there's some
sort of race condition. However, my test script is not multithreaded.

Does anyone with intimate knowledge of OBForceField have any idea what
could be happening? I'm using a recent build of trunk on linux.

Dave

------------------------------------------------------------------------------
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