Hi,
I found an example of BSP tree by Mr. Nathan from Dr. dobbs journal site, and seems it has some bugs as it crashes one of my same input file. The other bug i found is in the Split procedure
NewPoly1 = new CPoint[ PntCnt ]; NewPoly2 = new CPoint[ PntCnt ]; for( ushort i=0; i<PntCnt; i++ ) { // Handle split points if( Splits & ( 1 << i ) ) { NewPoly1[ Poly1Index++ ] = SplitPnts[ i ]; NewPoly2[ Poly2Index++ ] = SplitPnts[ i ]; Destination ^= 1; } if( Destination ) NewPoly1[ Poly1Index++ ] = PntList[ i ]; else NewPoly2[ Poly2Index++ ] = PntList[ i ]; }
If there are 4 points and 1 split was occured, newpoly1 will have 5 points but memory was allocated for 4 points only.
Is there something missing after “if( Splits & ( 1 << i ) )” part.
Please help me in writing or fixing a good BSP tree. I am stuck at transparency.
Thanks
DPS