Excellent stuff, I've put it into a test_hayne.cpp file, and attached it to a bug report.<br><br>Sylvain and I are debugging stuff stuff now, we'll add it to the test suite :)<br><br>thanks again,<br><font color="#888888">Paul<br>
</font><br><br><div class="gmail_quote">2008/11/11 Sam Hayne <span dir="ltr"><<a href="mailto:Sam.Hayne@gmx.de">Sam.Hayne@gmx.de</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>
Paul Harris wrote:<br>
<br>
> Hi Sam,<br>
<br>
> great email, lots of detail<br>
<br>
</div>Thx. If it helps you in any way I'm glad.<br>
(Hope those issues weren't all caused by VS or my edits. :D )<br>
<div class="Ih2E3d"><br>
> 3.1)<br>
> > I always ended up with runtime errors using erase(). :(<br>
<br>
> Could you please boil it down to a simple test case? (eg look at<br>
test_kdtree.cpp, just make up a new .cpp file that builds a tree and then ><br>
somehow crashes or asserts).<br>
<br>
<br>
</div>Puhh... wasn't that easy to create an simple example (as in my case I got<br>
the points out of a bitmap).<br>
But here a bit lengthy one - it crashes deterministically each time.<br>
<br>
In my case erase() failed to delete point (41, 189)... deleting some other<br>
point instead.<br>
Eventually resulting in this runtime error:<br>
<a href="http://img359.imageshack.us/img359/4623/runtimeerrordz4.jpg" target="_blank">http://img359.imageshack.us/img359/4623/runtimeerrordz4.jpg</a><br>
<br>
<br>
//=======<br>
//Defs:<br>
//========<br>
<div class="Ih2E3d"><br>
struct duplet {<br>
typedef int value_type;<br>
<br>
inline value_type operator[](size_t const N) const { return d[N]; }<br>
inline bool operator==(duplet const& other) const<br>
{<br>
return this->d[0] == other.d[0] && this->d[1] == other.d[1];<br>
<br>
}<br>
<br>
inline bool operator!=(duplet const& other) const<br>
{<br>
return this->d[0] != other.d[0] || this->d[1] != other.d[1];<br>
<br>
}<br>
<br>
value_type d[2];<br>
</div> //typedef boost::shared_ptr<duplet> ptr;<br>
};<br>
<div class="Ih2E3d"><br>
typedef KDTree::KDTree<2, duplet,<br>
std::pointer_to_binary_function<duplet,int,double> > duplet_tree_type;<br>
<br>
inline double return_dup( duplet d, int k ) { return d[k]; }<br>
<br>
<br>
<br>
<br>
</div>//=======<br>
//main:<br>
//========<br>
<div class="Ih2E3d"><br>
duplet_tree_type dupl_tree_test(std::ptr_fun(return_dup));<br>
</div> std::vector<duplet> vDuplets;<br>
<br>
//srand(time(0));<br>
int randy1 = 0;<br>
int randy2 = 0;<br>
for (int i=0; i<700; i++)<br>
{<br>
//create coordinate for new duplet<br>
randy1+=2;<br>
randy1=randy1%255;<br>
randy2+=3;<br>
randy2=randy2%255;<br>
//randy1 = rand() % 255;<br>
//randy2 = rand() % 255;<br>
<br>
//new duplet<br>
duplet super_dupre = { {randy1, randy2} };<br>
<br>
//check if duplet with same coordinate already in<br>
vector/tree. If not: insert in vector and tree<br>
<div class="Ih2E3d"> duplet_tree_type::iterator pItr =<br>
</div>dupl_tree_test.find_nearest(super_dupre,std::numeric_limits<double>::max()).<br>
first;<br>
if (*pItr!=super_dupre)<br>
{<br>
dupl_tree_test.insert(super_dupre);<br>
vDuplets.push_back(super_dupre);<br>
}<br>
<br>
}<br>
<br>
dupl_tree_test.optimise();<br>
<br>
int elements;<br>
<br>
while (vDuplets.size()>0) //delete all duplets from tree which are<br>
in the vector<br>
{<br>
elements = vDuplets.size();<br>
<br>
<br>
duplet element_to_erase = vDuplets.back();<br>
vDuplets.pop_back();<br>
<br>
dupl_tree_test.erase(element_to_erase); //erase() : will<br>
probably erase wrong element sooner or later<br>
//dupl_tree_test.erase_exact(element_to_erase);<br>
//erase_exact(): works<br>
<br>
<br>
//debug stuff:<br>
<div class="Ih2E3d"> duplet_tree_type::iterator pItr =<br>
</div>dupl_tree_test.find_nearest(element_to_erase,std::numeric_limits<double>::ma<br>
x()).first;<br>
duplet nearest_to_element = *pItr;<br>
if (nearest_to_element==element_to_erase)<br>
{<br>
// element still in tree... wrong element must have<br>
been erased<br>
int u = 7; //set breakpoint here<br>
}<br>
}<br>
<br>
<br>
</blockquote></div><br>