switch QList<> to QVector<> and add some guards against out of range indices

This commit is contained in:
ZappoMan 2014-10-15 20:18:04 -07:00
parent 01b64d78e3
commit 921a3fb8c0
2 changed files with 26 additions and 18 deletions

View file

@ -1393,7 +1393,7 @@ int Model::renderMeshes(RenderMode mode, bool translucent, float alphaThreshold,
bool cullMeshParts = args && !Menu::getInstance()->isOptionChecked(MenuOption::DontCullMeshParts);
// depending on which parameters we were called with, pick the correct mesh group to render
QList<int>* whichList = NULL;
QVector<int>* whichList = NULL;
if (translucent && !hasTangents && !hasSpecular && !isSkinned) {
whichList = &_meshesTranslucent;
} else if (translucent && hasTangents && !hasSpecular && !isSkinned) {
@ -1434,7 +1434,7 @@ int Model::renderMeshes(RenderMode mode, bool translucent, float alphaThreshold,
qDebug() << "unexpected!!! we don't know which list of meshes to render...";
return 0;
}
QList<int>& list = *whichList;
QVector<int>& list = *whichList;
ProgramObject* program = &_program;
Locations* locations = &_locations;
@ -1487,6 +1487,14 @@ int Model::renderMeshes(RenderMode mode, bool translucent, float alphaThreshold,
// i is the "index" from the original networkMeshes QVector...
foreach (int i, list) {
// if our index is ever out of range for either meshes or networkMeshes, then skip it, and set our _meshesGroupsKnown
// to false to rebuild out mesh groups.
if (i < 0 || i >= networkMeshes.size() || i > geometry.meshes.size()) {
_meshesGroupsKnown = false; // regenerate these lists next time around.
continue;
}
// exit early if the translucency doesn't match what we're drawing
const NetworkMesh& networkMesh = networkMeshes.at(i);
const FBXMesh& mesh = geometry.meshes.at(i);

View file

@ -337,25 +337,25 @@ private:
bool _meshesGroupsKnown;
QList<int> _meshesTranslucent;
QList<int> _meshesTranslucentTangents;
QList<int> _meshesTranslucentTangentsSpecular;
QList<int> _meshesTranslucentSpecular;
QVector<int> _meshesTranslucent;
QVector<int> _meshesTranslucentTangents;
QVector<int> _meshesTranslucentTangentsSpecular;
QVector<int> _meshesTranslucentSpecular;
QList<int> _meshesTranslucentSkinned;
QList<int> _meshesTranslucentTangentsSkinned;
QList<int> _meshesTranslucentTangentsSpecularSkinned;
QList<int> _meshesTranslucentSpecularSkinned;
QVector<int> _meshesTranslucentSkinned;
QVector<int> _meshesTranslucentTangentsSkinned;
QVector<int> _meshesTranslucentTangentsSpecularSkinned;
QVector<int> _meshesTranslucentSpecularSkinned;
QList<int> _meshesOpaque;
QList<int> _meshesOpaqueTangents;
QList<int> _meshesOpaqueTangentsSpecular;
QList<int> _meshesOpaqueSpecular;
QVector<int> _meshesOpaque;
QVector<int> _meshesOpaqueTangents;
QVector<int> _meshesOpaqueTangentsSpecular;
QVector<int> _meshesOpaqueSpecular;
QList<int> _meshesOpaqueSkinned;
QList<int> _meshesOpaqueTangentsSkinned;
QList<int> _meshesOpaqueTangentsSpecularSkinned;
QList<int> _meshesOpaqueSpecularSkinned;
QVector<int> _meshesOpaqueSkinned;
QVector<int> _meshesOpaqueTangentsSkinned;
QVector<int> _meshesOpaqueTangentsSpecularSkinned;
QVector<int> _meshesOpaqueSpecularSkinned;
};