T , 2011-10-12 15:42 -0400, David Lonie rakstīja:
> 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

Hi!

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.


Reinis


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