Removed various assert() instances since these were causing crashes.
From Alberto, changed the use of the DynGeoSet to it was querried on demand rather than used as a pointer which was originally being invalidate before use.
This commit is contained in:
@@ -1320,11 +1320,21 @@ void
|
|||||||
ConvertFromFLT::addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr )
|
ConvertFromFLT::addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr )
|
||||||
{
|
{
|
||||||
osg::Geometry* geom = dgset->getGeometry();
|
osg::Geometry* geom = dgset->getGeometry();
|
||||||
assert( geom );
|
|
||||||
assert( mtr );
|
if (geom==0 || mtr==0 || !mtr->isAncillaryRecord())
|
||||||
assert( mtr->isAncillaryRecord() );
|
{
|
||||||
|
osg::notify(osg::WARN)<<"ConvertFromFLT::addMultiTexture(DynGeoSet*, MultiTextureRecord*) has been passed invalid paramters."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SMultiTexture* mt = reinterpret_cast<SMultiTexture*>(mtr->getData());
|
SMultiTexture* mt = reinterpret_cast<SMultiTexture*>(mtr->getData());
|
||||||
assert( mt );
|
if (mt==0)
|
||||||
|
{
|
||||||
|
osg::notify(osg::WARN)<<"ConvertFromFLT::addMultiTexture(DynGeoSet*, MultiTextureRecord*) mtr->getData() not valid SMultiTexture*."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CERR << "ConvertFromFLT::addMultiTexture\n";
|
CERR << "ConvertFromFLT::addMultiTexture\n";
|
||||||
int l = 0;
|
int l = 0;
|
||||||
for ( int i = 0; i < 8; i++ )
|
for ( int i = 0; i < 8; i++ )
|
||||||
@@ -1339,7 +1349,14 @@ ConvertFromFLT::addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr )
|
|||||||
CERR << "data: " << mt->data[l].data << "\n";
|
CERR << "data: " << mt->data[l].data << "\n";
|
||||||
|
|
||||||
TexturePool* pTexturePool = mtr->getFltFile()->getTexturePool();
|
TexturePool* pTexturePool = mtr->getFltFile()->getTexturePool();
|
||||||
|
|
||||||
assert( pTexturePool );
|
assert( pTexturePool );
|
||||||
|
if (!pTexturePool)
|
||||||
|
{
|
||||||
|
osg::notify(osg::WARN)<<"ConvertFromFLT::addMultiTexture(DynGeoSet*, MultiTextureRecord*) pTexturePool invalid."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
osg::StateSet *textureStateSet = dynamic_cast<osg::StateSet *> (pTexturePool->getTexture((int)mt->data[l].texture,mtr->getFlightVersion()));
|
osg::StateSet *textureStateSet = dynamic_cast<osg::StateSet *> (pTexturePool->getTexture((int)mt->data[l].texture,mtr->getFlightVersion()));
|
||||||
|
|
||||||
CERR << "pTexturePool->getTexture((int)mt->data[l].texture): " << pTexturePool->getTexture((int)mt->data[l].texture,mtr->getFlightVersion()) << "\n";
|
CERR << "pTexturePool->getTexture((int)mt->data[l].texture): " << pTexturePool->getTexture((int)mt->data[l].texture,mtr->getFlightVersion()) << "\n";
|
||||||
@@ -1357,27 +1374,38 @@ ConvertFromFLT::addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr )
|
|||||||
osg::StateSet* texture_stateset = new osg::StateSet;
|
osg::StateSet* texture_stateset = new osg::StateSet;
|
||||||
CERR << "texture_stateset: " << texture_stateset << "\n";
|
CERR << "texture_stateset: " << texture_stateset << "\n";
|
||||||
|
|
||||||
assert( texture );
|
if (!texture)
|
||||||
texture_stateset->setTextureAttributeAndModes(
|
{
|
||||||
i, texture,osg::StateAttribute::ON);
|
osg::notify(osg::WARN)<<"ConvertFromFLT::addMultiTexture(DynGeoSet*, MultiTextureRecord*) texture invalid."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
osg::TexEnv* osgTexEnv = new osg::TexEnv;
|
|
||||||
CERR << "osgTexEnv: " << osgTexEnv << "\n";
|
|
||||||
osgTexEnv->setMode(osg::TexEnv::MODULATE);
|
|
||||||
texture_stateset->setTextureAttribute( i, osgTexEnv );
|
|
||||||
|
|
||||||
assert( geom );
|
texture_stateset->setTextureAttributeAndModes(
|
||||||
CERR << "geom: " << geom << "\n";
|
i, texture,osg::StateAttribute::ON);
|
||||||
CERR << ", referenceCount: "
|
|
||||||
<< geom->referenceCount() << "\n";
|
osg::TexEnv* osgTexEnv = new osg::TexEnv;
|
||||||
|
|
||||||
|
CERR << "osgTexEnv: " << osgTexEnv << "\n";
|
||||||
|
|
||||||
|
osgTexEnv->setMode(osg::TexEnv::MODULATE);
|
||||||
|
texture_stateset->setTextureAttribute( i, osgTexEnv );
|
||||||
|
|
||||||
|
CERR << "geom: " << geom << "\n";
|
||||||
|
CERR << ", referenceCount: "
|
||||||
|
<< geom->referenceCount() << "\n";
|
||||||
|
|
||||||
osg::StateSet* geom_stateset = geom->getStateSet();
|
osg::StateSet* geom_stateset = geom->getStateSet();
|
||||||
CERR << "geom_stateset: " << geom_stateset << "\n";
|
|
||||||
if ( geom_stateset ) {
|
CERR << "geom_stateset: " << geom_stateset << "\n";
|
||||||
geom_stateset->merge( *texture_stateset );
|
|
||||||
CERR << "Merging layer " << i << "\n";
|
if ( geom_stateset )
|
||||||
|
{
|
||||||
|
geom_stateset->merge( *texture_stateset );
|
||||||
|
CERR << "Merging layer " << i << "\n";
|
||||||
} else {
|
} else {
|
||||||
geom->setStateSet( texture_stateset );
|
geom->setStateSet( texture_stateset );
|
||||||
CERR << "Setting layer " << i << "\n";
|
CERR << "Setting layer " << i << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
l++;
|
l++;
|
||||||
@@ -1389,35 +1417,47 @@ void
|
|||||||
ConvertFromFLT::addUVList( DynGeoSet* dgset, UVListRecord* uvr )
|
ConvertFromFLT::addUVList( DynGeoSet* dgset, UVListRecord* uvr )
|
||||||
{
|
{
|
||||||
osg::Geometry* geom = dgset->getGeometry();
|
osg::Geometry* geom = dgset->getGeometry();
|
||||||
assert( geom );
|
|
||||||
assert( uvr );
|
if (!geom || !uvr || !uvr->isAncillaryRecord())
|
||||||
assert( uvr->isAncillaryRecord() );
|
{
|
||||||
SUVList* uvl =
|
osg::notify(osg::WARN)<<"ConvertFromFLT::addUVList( DynGeoSet*, UVListRecord*) has been passed invalid paramters."<<std::endl;
|
||||||
reinterpret_cast<SUVList*>(uvr->getData());
|
return;
|
||||||
assert( uvl );
|
}
|
||||||
|
|
||||||
|
SUVList* uvl = reinterpret_cast<SUVList*>(uvr->getData());
|
||||||
|
if (!uvl)
|
||||||
|
{
|
||||||
|
osg::notify(osg::WARN)<<"ConvertFromFLT::addUVList( DynGeoSet*, UVListRecord*) uvr->getData() is invalid."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CERR << "ConvertFromFLT::addUVList\n";
|
CERR << "ConvertFromFLT::addUVList\n";
|
||||||
int l = 0;
|
int l = 0;
|
||||||
int num_coords = dgset->coordListSize();
|
int num_coords = dgset->coordListSize();
|
||||||
for ( int i = 0; i < 8; i++ ) {
|
for ( int i = 0; i < 8; i++ )
|
||||||
if ( (1 << (32-i)) & uvl->layers ) {
|
{
|
||||||
osg::Vec2Array* tcoords = new osg::Vec2Array;
|
if ( (1 << (32-i)) & uvl->layers )
|
||||||
CERR << "Has layer " << i << "\n";
|
{
|
||||||
// Assume we are working with vertex lists for now
|
osg::Vec2Array* tcoords = new osg::Vec2Array;
|
||||||
for ( int v = l*num_coords; v < (l+1)*num_coords; v++ ) {
|
CERR << "Has layer " << i << "\n";
|
||||||
uvl->coords.vertex[v].endian();
|
// Assume we are working with vertex lists for now
|
||||||
CERR << "( u: " << uvl->coords.vertex[v].coords[1] << ", "
|
for ( int v = l*num_coords; v < (l+1)*num_coords; v++ )
|
||||||
<< "v: " << uvl->coords.vertex[v].coords[0] << ")\n";
|
{
|
||||||
/// FIXME: should be (x,y) instead of (y,x) - ENDIAN problem???
|
uvl->coords.vertex[v].endian();
|
||||||
tcoords->push_back( osg::Vec2( uvl->coords.vertex[v].coords[1],
|
CERR << "( u: " << uvl->coords.vertex[v].coords[1] << ", "
|
||||||
uvl->coords.vertex[v].coords[0] ) );
|
<< "v: " << uvl->coords.vertex[v].coords[0] << ")\n";
|
||||||
}
|
/// FIXME: should be (x,y) instead of (y,x) - ENDIAN problem???
|
||||||
if ( !tcoords->empty() ) {
|
tcoords->push_back( osg::Vec2( uvl->coords.vertex[v].coords[1],
|
||||||
CERR << "Setting tcoords " << i << ": " << tcoords << "\n";
|
uvl->coords.vertex[v].coords[0] ) );
|
||||||
geom->setTexCoordArray( i, tcoords );
|
}
|
||||||
}
|
if ( !tcoords->empty() )
|
||||||
|
{
|
||||||
|
CERR << "Setting tcoords " << i << ": " << tcoords << "\n";
|
||||||
|
geom->setTexCoordArray( i, tcoords );
|
||||||
|
}
|
||||||
|
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1481,8 +1521,16 @@ void ConvertFromFLT::visitFace(GeoSetBuilder* pBuilder, FaceRecord* rec)
|
|||||||
{
|
{
|
||||||
MultiTextureRecord* mtr =
|
MultiTextureRecord* mtr =
|
||||||
dynamic_cast<MultiTextureRecord*>(child);
|
dynamic_cast<MultiTextureRecord*>(child);
|
||||||
assert( mtr );
|
if (!mtr)
|
||||||
addMultiTexture( dgset, mtr );
|
{
|
||||||
|
osg::notify( osg::WARN ) << "flt::ConvertFromFLT::visitFace(GeoSetBuilder*, FaceRecord*) found invalid MultiTextureRecord*"<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// original code, but causes crash becayse addPrimitive can invalidate teh dgset pointer.
|
||||||
|
// addMultiTexture( dgset, mtr );
|
||||||
|
|
||||||
|
addMultiTexture( pBuilder->getDynGeoSet(), mtr );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user