On Mon, May 7, 2012 at 10:09 AM, Geoffrey Hutchison <geo...@pitt.edu> wrote:
>
> On May 4, 2012, at 10:45 PM, Craig James wrote:
>
> > But it seems to be the atom iterator, not the ring iterator, that's
> causing the problem.
>
> Huh. Here's comparable code in forcefieldmmff94.cpp:
>
> for(rj = (*ri)->_path.begin();rj != (*ri)->_path.end();rj++) { // for
> each ring atom
> index = *rj;
> ringatom = _mol.GetAtom(index);
>
> Granted, like Igor's comment the code gets the rings like so:
>
> vector<OBRing*> vr;
> vr = _mol.GetSSSR();
>
> Have you checked the path size?
>
It's a random number. Here is a more concise version of the code ... it's
extracted from a much larger body of code, but I think I got all the
relevant parts.
OBMol *pmol;
OBConversion conv;
conv.SetInAndOutFormats("sdf", "smi");
pmol = new OBMol;
pmol->Clear();
conv.ReadString(pmol, molData_str);
natoms = pmol->NumAtoms();
nbonds = pmol->NumBonds();
if (natoms <= 0) { // No atoms? (shouldn't happen...)
return 0;
}
for (atom = pmol->BeginAtom(ai); atom; atom = pmol->NextAtom(ai)) {
float x = atom->GetX();
float y = atom->GetY();
// --- snip --- code to draw atom labels into image
}
// --- snip --- initialize code for GIF/JPG/PNG library
vector<OBRing*> rlist = mol->GetSSSR();
vector<OBRing*>::iterator ri;
for (ri = rlist.begin(); ri != rlist.end(); ++ri) {
fprintf(stderr, "_path.size() = %d\n", (*ri)->_path.size());
// Prints out a big random negative number
vector<int>::iterator j;
for (j = (*ri)->_path.begin(); j != (*ri)->_path.end(); j++) {
OBAtom *atom = mol->GetAtom(*j);
// .... crashes because j is NULL
}
}
I ran valgrind on it which is usually very good at finding problems. When
it gets to where I print _path.size(), valgrind complains that I'm printing
uninitialized memory, and the value that comes out is indeed a random value
(-1067674809 or 0x3FA36CB9). valgrind doesn't report any other errors at
all.
I'm stumped, but I'm happy to help,
>
Thanks ... I suspect this will turn out to be a bug somewhere else in the
program (overwriting a buffer or something, but in a way that valgrind
can't detect), but for the life of me I can't find it. It worked for
OpenBabel 2.2.x and now fails for OpenBabel 2.3.x.
Mostly I'm just asking if I'm calling the OpenBabel functions correctly.
It sounds like I am. That being the case, I'll start digging around in the
rest of my code to find the bug.
Craig
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel