On Wed, Oct 12, 2011 at 3:25 PM, David Lonie <lonieda...@gmail.com> wrote:
> 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.
> <snip>
> 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.
I've attached a minimal working example to this email that shows this
behavior. Compile with
g++ -I/usr/include/openbabel-2.0 -lopenbabel obfftest.cpp -g
(change the include path as appropriate, of course)
It will segfault when run, crashing when bar's setupForceField method
is called, specifically in the MakeNewInstance line.
> 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.
Removing the "delete m_ff; m_ff = NULL;" bit from ~MyClass will let
the example run with no problems.
Let me know if any more information would help.
Dave
> 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
>
#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;
}
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