Skip to content

Fix pointer aliasing in kdtree #36

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

Merged
merged 1 commit into from
Apr 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Demos/Simulation/kdTree.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include "BoundingSphere.h"
#include <cstring>
#include "omp.h"

template<typename HullType> void
Expand Down Expand Up @@ -127,8 +128,10 @@ KDTree<HullType>::traverse_breadth_first_parallel(TraversalPredicate pred,
#endif

// compute ceiling of Log2
Real d = maxThreads - 1;
const unsigned int targetDepth = (*reinterpret_cast<long long*>(&d) >> 52) - 1022;
// assuming double and long long have the same size.
double d = maxThreads - 1;
long long ll; memcpy( &ll, &d, sizeof(d));
const unsigned int targetDepth = (ll >> 52) - 1022ll;

traverse_breadth_first(
[&start_nodes, &maxThreads, &targetDepth](unsigned int node_index, unsigned int depth)
Expand Down Expand Up @@ -207,4 +210,4 @@ KDTree<HullType>::update()
compute_hull_approx(nd.begin, nd.n, m_hulls[node_index]);
}
);
}
}