NewBitFlag Function shifted an 16 Bit Integer with << 1. The DeleteBitFlag Function shifted with >> 1. If a programmer forget after a call of NewBitFlag to call DeleteBitFlag the system generate an overflow and set the 16 Bit value to 0. The Effects of this operation are manifold. In our Program the program crash.
In Clean.h we search to CountNonManifoldEdgeFF(). In CountNonManifoldEdgeFF() three new BitFlags are generated:
Line 639: nmfBit[0] = FaceType::NewBitFlag();
Line 640: nmfBit[1] = FaceType::NewBitFlag();
Line 641: nmfBit[2] = FaceType::NewBitFlag();
and no call to DeleteBitFlag. Now I add:
Add Line 685: FaceType::DeleteBitFlag(nmfBit[2]);
Add Line 686: FaceType::DeleteBitFlag(nmfBit[1]);
Add Line 687: FaceType::DeleteBitFlag(nmfBit[0]);
to close these dangerous overflow. But we should have a class like this:
class BitFlagHelper
{
public:
BitFlagHelper()
{
theValue = FaceType::NewBitFlag();
}
~BitFlagHelper()
{
// FaceType::DeleteBitFlag(theValue); /* Old way */
FaceType::DeleteBitFlag();
}
int GetValue() { return theValue; }
private:
int theValue;
};
Then we have to instance a class for generate a new BitFlag and these class cleaned by themself. But then we should change the DeleteBitFlag() funtion from:
static inline bool DeleteBitFlag(int bitval)
{
if(LastBitFlag() == bitval)
{
LastBitFlag() = LastBitFlag() >> 1;
return true;
}
assert(0);
return false;
}
to:
static inline bool DeleteBitFlag()
{
LastBitFlag() = LastBitFlag() >> 1;
return true;
}