Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN coordinates crash coordgen #124

Open
bjonnh-work opened this issue Jul 17, 2023 · 0 comments
Open

NaN coordinates crash coordgen #124

bjonnh-work opened this issue Jul 17, 2023 · 0 comments

Comments

@bjonnh-work
Copy link

Related to : rdkit/rdkit#4845 (@greglandrum) and #106

On arm64 only (this doesn't happen on amd64), we see failures in
sketcherMinimizerAtom::clockwiseOrderedNeighbors (in sketcherMinimizerAtom)
where sketcherMinimizerMaths::signedAngle returns NaN but this method can't handle it.
What happens is that the loop doesn't trigger the if that sets lastPoppedIndex so it keeps the value to its previous one.

when the value was 1, and neighs only has one element left, it tries to delete an element out of the vector. And when the glibc destructor hits at the exit of the function we get a
"double free or corruption (out)".

By resetting lastPoppedIndex to 0 before that loop, we avoid the issue and the tests pass (at least the rdkit ones).

while (neighs.size()) {
        float smallestAngle = 361;
        lastPoppedIndex = 0;
        for (unsigned int i = 0; i < neighs.size(); i++) {
            float newAngle = sketcherMinimizerMaths::signedAngle(
                lastPoppedAtom->coordinates, coordinates,
                neighs[i]->coordinates);
            if (newAngle < 0) {
                newAngle += 360;
            }
            if (newAngle < smallestAngle) {
                smallestAngle = newAngle;
                lastPoppedIndex = i;
            }
        }
        lastPoppedAtom = neighs[lastPoppedIndex];
        orderedNeighs.push_back(lastPoppedAtom);
        neighs.erase(neighs.begin() + lastPoppedIndex);
    }

We could also check for NaN and set to 0 in that specific case.

I can make a PR if you think that's a viable solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant