Skip to content

Commit

Permalink
#912 BugSplat Crash 1412267: nvoglv64+0xadcd00
Browse files Browse the repository at this point in the history
  • Loading branch information
LLGuru committed Apr 15, 2024
1 parent 8f0c41c commit e4dd93e
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 160 deletions.
44 changes: 18 additions & 26 deletions indra/llprimitive/lldaeloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#include <boost/regex.hpp>
#include <boost/algorithm/string/replace.hpp>

std::string colladaVersion[VERSIONTYPE_COUNT+1] =
std::string colladaVersion[VERSIONTYPE_COUNT+1] =
{
"1.4.0",
"1.4.1",
Expand Down Expand Up @@ -1119,22 +1119,20 @@ bool LLDAELoader::OpenFile(const std::string& filename)
{ //add skinned meshes as instances
domSkin* skin = NULL;
db->getElement((daeElement**) &skin, idx, NULL, COLLADA_TYPE_SKIN);

if (skin)
{
domGeometry* geom = daeSafeCast<domGeometry>(skin->getSource().getElement());

if (geom)
if (domGeometry* geom = daeSafeCast<domGeometry>(skin->getSource().getElement()))
{
domMesh* mesh = geom->getMesh();
if (mesh)
if (domMesh* mesh = geom->getMesh())
{
std::vector< LLPointer< LLModel > >::iterator i = mModelsMap[mesh].begin();
while (i != mModelsMap[mesh].end())
dae_model_map::const_iterator it = mModelsMap.find(mesh);
if (it != mModelsMap.end())
{
LLPointer<LLModel> mdl = *i;
LLDAELoader::processDomModel(mdl, &dae, root, mesh, skin);
i++;
for (const LLPointer<LLModel>& model : it->second)
{
LLDAELoader::processDomModel(model, &dae, root, mesh, skin);
}
}
}
}
Expand Down Expand Up @@ -1304,6 +1302,7 @@ void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, do
}
}
else
{
//Has one or more skeletons
for (std::vector<domInstance_controller::domSkeleton*>::iterator skel_it = skeletons.begin();
skel_it != skeletons.end(); ++skel_it)
Expand Down Expand Up @@ -1388,6 +1387,7 @@ void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, do
}
}//got skeleton?
}
}


domSkin::domJoints* joints = skin->getJoints();
Expand Down Expand Up @@ -1688,7 +1688,7 @@ void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, do
materials[model->mMaterialList[i]] = LLImportMaterial();
}
mScene[transformation].push_back(LLModelInstance(model, model->mLabel, transformation, materials));
stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform);
stretch_extents(model, transformation);
}
}

Expand Down Expand Up @@ -2081,21 +2081,14 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
mTransform.condition();
}

domInstance_geometry* instance_geo = daeSafeCast<domInstance_geometry>(element);
if (instance_geo)
if (domInstance_geometry* instance_geo = daeSafeCast<domInstance_geometry>(element))
{
domGeometry* geo = daeSafeCast<domGeometry>(instance_geo->getUrl().getElement());
if (geo)
if (domGeometry* geo = daeSafeCast<domGeometry>(instance_geo->getUrl().getElement()))
{
domMesh* mesh = daeSafeCast<domMesh>(geo->getDescendant(daeElement::matchType(domMesh::ID())));
if (mesh)
if (domMesh* mesh = daeSafeCast<domMesh>(geo->getDescendant(daeElement::matchType(domMesh::ID()))))
{

std::vector< LLPointer< LLModel > >::iterator i = mModelsMap[mesh].begin();
while (i != mModelsMap[mesh].end())
for (LLModel* model : mModelsMap.find(mesh)->second)
{
LLModel* model = *i;

LLMatrix4 transformation = mTransform;

if (mTransform.determinant() < 0)
Expand Down Expand Up @@ -2166,8 +2159,7 @@ void LLDAELoader::processElement( daeElement* element, bool& badElement, DAE* da
}

mScene[transformation].push_back(LLModelInstance(model, label, transformation, materials));
stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform);
i++;
stretch_extents(model, transformation);
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions indra/llprimitive/llmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,15 @@ std::string LLModel::getStatusString(U32 status)
}


void LLModel::offsetMesh( const LLVector3& pivotPoint )
void LLModel::offsetMesh(const LLVector3& pivotPoint)
{
LLVector4a pivot( pivotPoint[VX], pivotPoint[VY], pivotPoint[VZ] );
for (std::vector<LLVolumeFace>::iterator faceIt = mVolumeFaces.begin(); faceIt != mVolumeFaces.end(); )
LLVector4a pivot(pivotPoint[VX], pivotPoint[VY], pivotPoint[VZ]);

for (LLVolumeFace& face : mVolumeFaces)
{
std::vector<LLVolumeFace>:: iterator currentFaceIt = faceIt++;
LLVolumeFace& face = *currentFaceIt;
LLVector4a *pos = (LLVector4a*) face.mPositions;

for (U32 i=0; i<face.mNumVertices; ++i )
for (U32 i = 0; i < face.mNumVertices; ++i)
{
pos[i].add( pivot );
face.mPositions[i].add(pivot);
}
}
}
Expand Down Expand Up @@ -337,7 +333,7 @@ void LLModel::normalizeVolumeFaces()
}
}

void LLModel::getNormalizedScaleTranslation(LLVector3& scale_out, LLVector3& translation_out)
void LLModel::getNormalizedScaleTranslation(LLVector3& scale_out, LLVector3& translation_out) const
{
scale_out = mNormalizedScale;
translation_out = mNormalizedTranslation;
Expand Down
6 changes: 3 additions & 3 deletions indra/llprimitive/llmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ class LLModel : public LLVolume
void trimVolumeFacesToSize(U32 new_count = LL_SCULPT_MESH_MAX_FACES, LLVolume::face_list_t* remainder = NULL);
void remapVolumeFaces();
void optimizeVolumeFaces();
void offsetMesh( const LLVector3& pivotPoint );
void getNormalizedScaleTranslation(LLVector3& scale_out, LLVector3& translation_out);
void offsetMesh(const LLVector3& pivotPoint);
void getNormalizedScaleTranslation(LLVector3& scale_out, LLVector3& translation_out) const;
LLVector3 getTransformedCenter(const LLMatrix4& mat);

//reorder face list based on mMaterialList in this and reference so
Expand Down Expand Up @@ -365,7 +365,7 @@ class LLModelInstanceBase
{
public:
LLPointer<LLModel> mModel;
LLPointer<LLModel> mLOD[5];
LLPointer<LLModel> mLOD[LLModel::NUM_LODS];
LLUUID mMeshID;

LLMatrix4 mTransform;
Expand Down
33 changes: 13 additions & 20 deletions indra/llprimitive/llmodelloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

std::list<LLModelLoader*> LLModelLoader::sActiveLoaderList;

void stretch_extents(LLModel* model, LLMatrix4a& mat, LLVector4a& min, LLVector4a& max, BOOL& first_transform)
static void stretch_extents(const LLModel* model, const LLMatrix4a& mat, LLVector4a& min, LLVector4a& max, bool& first_transform)
{
LLVector4a box[] =
{
Expand All @@ -59,7 +59,7 @@ void stretch_extents(LLModel* model, LLMatrix4a& mat, LLVector4a& min, LLVector4
center.setAdd(face.mExtents[0], face.mExtents[1]);
center.mul(0.5f);
LLVector4a size;
size.setSub(face.mExtents[1],face.mExtents[0]);
size.setSub(face.mExtents[1], face.mExtents[0]);
size.mul(0.5f);

for (U32 i = 0; i < 8; i++)
Expand All @@ -74,7 +74,7 @@ void stretch_extents(LLModel* model, LLMatrix4a& mat, LLVector4a& min, LLVector4

if (first_transform)
{
first_transform = FALSE;
first_transform = false;
min = max = v;
}
else
Expand All @@ -85,19 +85,19 @@ void stretch_extents(LLModel* model, LLMatrix4a& mat, LLVector4a& min, LLVector4
}
}

void stretch_extents(LLModel* model, LLMatrix4& mat, LLVector3& min, LLVector3& max, BOOL& first_transform)
void LLModelLoader::stretch_extents(const LLModel* model, const LLMatrix4& mat)
{
LLVector4a mina, maxa;
LLMatrix4a mata;

mata.loadu(mat);
mina.load3(min.mV);
maxa.load3(max.mV);
mina.load3(mExtents[0].mV);
maxa.load3(mExtents[1].mV);

stretch_extents(model, mata, mina, maxa, first_transform);
::stretch_extents(model, mata, mina, maxa, mFirstTransform);

min.set(mina.getF32ptr());
max.set(maxa.getF32ptr());
mExtents[0].set(mina.getF32ptr());
mExtents[1].set(maxa.getF32ptr());
}

//-----------------------------------------------------------------------------
Expand All @@ -121,7 +121,7 @@ LLModelLoader::LLModelLoader(
, mFilename(filename)
, mLod(lod)
, mTrySLM(false)
, mFirstTransform(TRUE)
, mFirstTransform(true)
, mNumOfFetchingTextures(0)
, mLoadCallback(load_cb)
, mJointLookupFunc(joint_lookup_func)
Expand Down Expand Up @@ -292,14 +292,7 @@ bool LLModelLoader::loadFromSLM(const std::string& filename)
{
if (idx >= model[lod].size())
{
if (model[lod].size())
{
instance_list[i].mLOD[lod] = model[lod][0];
}
else
{
instance_list[i].mLOD[lod] = NULL;
}
instance_list[i].mLOD[lod] = model[lod].front();
continue;
}

Expand Down Expand Up @@ -337,12 +330,12 @@ bool LLModelLoader::loadFromSLM(const std::string& filename)


//convert instance_list to mScene
mFirstTransform = TRUE;
mFirstTransform = true;
for (U32 i = 0; i < instance_list.size(); ++i)
{
LLModelInstance& cur_instance = instance_list[i];
mScene[cur_instance.mTransform].push_back(cur_instance);
stretch_extents(cur_instance.mModel, cur_instance.mTransform, mExtents[0], mExtents[1], mFirstTransform);
stretch_extents(cur_instance.mModel, cur_instance.mTransform);
}

setLoadState( DONE );
Expand Down
45 changes: 21 additions & 24 deletions indra/llprimitive/llmodelloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@

class LLJoint;

typedef std::map<std::string, LLMatrix4> JointTransformMap;
typedef std::map<std::string, LLMatrix4>::iterator JointTransformMapIt;
typedef std::map<std::string, std::string> JointMap;
typedef std::deque<std::string> JointNameSet;
typedef std::map<std::string, LLMatrix4> JointTransformMap;
typedef std::map<std::string, LLMatrix4>::iterator JointTransformMapIt;
typedef std::map<std::string, std::string> JointMap;
typedef std::deque<std::string> JointNameSet;

const S32 SLM_SUPPORTED_VERSION = 3;
const S32 NUM_LOD = 4;
const S32 NUM_LOD = 4;

const U32 LEGACY_RIG_OK = 0;
const U32 LEGACY_RIG_FLAG_TOO_MANY_JOINTS = 1;
Expand All @@ -50,32 +50,32 @@ class LLModelLoader : public LLThread
{
public:

typedef std::map<std::string, LLImportMaterial> material_map;
typedef std::vector<LLPointer<LLModel > > model_list;
typedef std::vector<LLModelInstance> model_instance_list;
typedef std::map<LLMatrix4, model_instance_list > scene;
typedef std::map<std::string, LLImportMaterial> material_map;
typedef std::vector<LLPointer<LLModel>> model_list;
typedef std::vector<LLModelInstance> model_instance_list;
typedef std::map<LLMatrix4, model_instance_list> scene;

// Callback with loaded model data and loaded LoD
//
typedef boost::function<void (scene&,model_list&,S32,void*) > load_callback_t;
//
typedef boost::function<void (scene&, model_list&, S32, void*)> load_callback_t;

// Function to provide joint lookup by name
// (within preview avi skeleton, for example)
//
typedef boost::function<LLJoint* (const std::string&,void*) > joint_lookup_func_t;
typedef boost::function<LLJoint* (const std::string&, void*)> joint_lookup_func_t;

// Func to load and associate material with all it's textures,
// returned value is the number of textures loaded
// intentionally non-const so func can modify material to
// store platform-specific data
//
typedef boost::function<U32 (LLImportMaterial&,void*) > texture_load_func_t;
typedef boost::function<U32 (LLImportMaterial&, void*)> texture_load_func_t;

// Callback to inform client of state changes
// during loading process (errors will be reported
// as state changes here as well)
//
typedef boost::function<void (U32,void*) > state_callback_t;
typedef boost::function<void (U32, void*)> state_callback_t;

typedef enum
{
Expand Down Expand Up @@ -104,7 +104,7 @@ class LLModelLoader : public LLThread
S32 mLod;

LLMatrix4 mTransform;
BOOL mFirstTransform;
bool mFirstTransform;
LLVector3 mExtents[2];

bool mTrySLM;
Expand Down Expand Up @@ -136,7 +136,7 @@ class LLModelLoader : public LLThread
JointNameSet& jointsFromNodes,
JointMap& legalJointNamesMap,
U32 maxJointsPerMesh);
virtual ~LLModelLoader() ;
virtual ~LLModelLoader();

virtual void setNoNormalize() { mNoNormalize = true; }
virtual void setNoOptimize() { mNoOptimize = true; }
Expand All @@ -156,13 +156,13 @@ class LLModelLoader : public LLThread
bool loadFromSLM(const std::string& filename);

void loadModelCallback();
void loadTextures() ; //called in the main thread.
void loadTextures(); // called in the main thread.
void setLoadState(U32 state);


void stretch_extents(const LLModel* model, const LLMatrix4& mat);

S32 mNumOfFetchingTextures ; //updated in the main thread
bool areTexturesReady() { return !mNumOfFetchingTextures; } //called in the main thread.
S32 mNumOfFetchingTextures; // updated in the main thread
bool areTexturesReady() { return !mNumOfFetchingTextures; } // called in the main thread.

bool verifyCount( int expected, int result );

Expand Down Expand Up @@ -212,10 +212,7 @@ class LLModelLoader : public LLThread
LLSD mWarningsArray; // preview floater will pull logs from here

static std::list<LLModelLoader*> sActiveLoaderList;
static bool isAlive(LLModelLoader* loader) ;
static bool isAlive(LLModelLoader* loader);
};
class LLMatrix4a;
void stretch_extents(LLModel* model, LLMatrix4a& mat, LLVector4a& min, LLVector4a& max, BOOL& first_transform);
void stretch_extents(LLModel* model, LLMatrix4& mat, LLVector3& min, LLVector3& max, BOOL& first_transform);

#endif // LL_LLMODELLOADER_H
Loading

0 comments on commit e4dd93e

Please sign in to comment.