On Wed, Oct 12, 2011 at 4:53 PM, My Th <rei4...@gmail.com> wrote:
> 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.
>>
> 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.

Can someone add this to the sources? I would, but I'm a bit too
unfamiliar with this part of OB to know if this should go in
ForceFieldUFF, ForceField, Plugin, ... or if there are any side
effects from this fix.

Thanks,

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