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:
Robert Osfield
2003-04-18 10:10:14 +00:00
parent dac86dabb5
commit 1c8db044f1

View File

@@ -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,22 +1374,33 @@ 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)
{
osg::notify(osg::WARN)<<"ConvertFromFLT::addMultiTexture(DynGeoSet*, MultiTextureRecord*) texture invalid."<<std::endl;
return;
}
texture_stateset->setTextureAttributeAndModes( texture_stateset->setTextureAttributeAndModes(
i, texture,osg::StateAttribute::ON); i, texture,osg::StateAttribute::ON);
osg::TexEnv* osgTexEnv = new osg::TexEnv; osg::TexEnv* osgTexEnv = new osg::TexEnv;
CERR << "osgTexEnv: " << osgTexEnv << "\n"; CERR << "osgTexEnv: " << osgTexEnv << "\n";
osgTexEnv->setMode(osg::TexEnv::MODULATE); osgTexEnv->setMode(osg::TexEnv::MODULATE);
texture_stateset->setTextureAttribute( i, osgTexEnv ); texture_stateset->setTextureAttribute( i, osgTexEnv );
assert( geom );
CERR << "geom: " << geom << "\n"; CERR << "geom: " << geom << "\n";
CERR << ", referenceCount: " CERR << ", referenceCount: "
<< geom->referenceCount() << "\n"; << geom->referenceCount() << "\n";
osg::StateSet* geom_stateset = geom->getStateSet(); osg::StateSet* geom_stateset = geom->getStateSet();
CERR << "geom_stateset: " << geom_stateset << "\n"; CERR << "geom_stateset: " << geom_stateset << "\n";
if ( geom_stateset ) {
if ( geom_stateset )
{
geom_stateset->merge( *texture_stateset ); geom_stateset->merge( *texture_stateset );
CERR << "Merging layer " << i << "\n"; CERR << "Merging layer " << i << "\n";
} else { } else {
@@ -1389,21 +1417,32 @@ 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 ) { {
if ( (1 << (32-i)) & uvl->layers )
{
osg::Vec2Array* tcoords = new osg::Vec2Array; osg::Vec2Array* tcoords = new osg::Vec2Array;
CERR << "Has layer " << i << "\n"; CERR << "Has layer " << i << "\n";
// Assume we are working with vertex lists for now // Assume we are working with vertex lists for now
for ( int v = l*num_coords; v < (l+1)*num_coords; v++ ) { for ( int v = l*num_coords; v < (l+1)*num_coords; v++ )
{
uvl->coords.vertex[v].endian(); uvl->coords.vertex[v].endian();
CERR << "( u: " << uvl->coords.vertex[v].coords[1] << ", " CERR << "( u: " << uvl->coords.vertex[v].coords[1] << ", "
<< "v: " << uvl->coords.vertex[v].coords[0] << ")\n"; << "v: " << uvl->coords.vertex[v].coords[0] << ")\n";
@@ -1411,7 +1450,8 @@ ConvertFromFLT::addUVList( DynGeoSet* dgset, UVListRecord* uvr )
tcoords->push_back( osg::Vec2( uvl->coords.vertex[v].coords[1], tcoords->push_back( osg::Vec2( uvl->coords.vertex[v].coords[1],
uvl->coords.vertex[v].coords[0] ) ); uvl->coords.vertex[v].coords[0] ) );
} }
if ( !tcoords->empty() ) { if ( !tcoords->empty() )
{
CERR << "Setting tcoords " << i << ": " << tcoords << "\n"; CERR << "Setting tcoords " << i << ": " << tcoords << "\n";
geom->setTexCoordArray( i, tcoords ); geom->setTexCoordArray( i, tcoords );
} }
@@ -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;