|
今天发现了发现OSG2.9.6版的一个小BUG,当创建一个AutoTransform节点并保存为Ive文件的时候,若你的是在开发成AxtiveX的情况下,系统会崩溃,当你开发的是Exe程序,则表面上没有问题,但数据是有错的
仔细查看了一下源代码,发现AutoTransform在2.9.6里面被改成了有几个成员变量被改成了Double型,_maximumScale就是其中一个,在构造函数里面
AutoTransform::AutoTransform():
_autoUpdateEyeMovementTolerance(0.0f),
_autoRotateMode(NO_ROTATION),
_autoScaleToScreen(false),
_scale(1.0f,1.0f,1.0f),
_firstTimeToInitEyePoint(true),
_minimumScale(0.0f),
_maximumScale(DBL_MAX),
_autoScaleTransitionWidthRatio(0.25f),
_matrixDirty(true)
{
// setNumChildrenRequiringUpdateTraversal(1);
}
他被初始化为_maximumScale(DBL_MAX)最大的double型,
再看看IVE插件的保存代码
void AutoTransform::write(DataOutputStream* out){
// Write AutoTransform's identification.
out->writeInt(IVEAUTOTRANSFORM);
// If the osg class is inherited by any other class we should also write this to file.
osg::Transform* trans = dynamic_cast<osg::Transform*>(this);
if(trans){
((ive::Transform*)(trans))->write(out);
}
else
throw Exception("AutoTransform::write(): Could not cast this osg::AutoTransform to an osg::Transform.");
// Write AutoTransform's properties.
out->writeVec3(getPosition());
out->writeVec3(getPivotPoint());
out->writeFloat(getAutoUpdateEyeMovementTolerance());
out->writeInt(getAutoRotateMode());
out->writeBool(getAutoScaleToScreen());
if ( out->getVersion() >= VERSION_0025 )
{
out->writeFloat(getMinimumScale());
out->writeFloat(getMaximumScale());
out->writeFloat(getAutoScaleTransitionWidthRatio());
}
out->writeQuat(getRotation());
out->writeVec3(getScale());
}
其中out->writeFloat(getMaximumScale())等还都是用Float型保存的,导致转换成Float型时溢出出错,在某些情况下会导致系统崩溃,即使系统不崩溃,再读出来的 _maximumScale也讲完全错误,而导致不可预料的事情发生。
另,也许这种类似转换的错误还不少,忘有心人到官网上去提一下,我不知道在哪里提,所以在这里说一下,谢谢 |
|