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); bool cullMeshParts = args && !Menu::getInstance()->isOptionChecked(MenuOption::DontCullMeshParts);
// depending on which parameters we were called with, pick the correct mesh group to render // 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) { if (translucent && !hasTangents && !hasSpecular && !isSkinned) {
whichList = &_meshesTranslucent; whichList = &_meshesTranslucent;
} else if (translucent && hasTangents && !hasSpecular && !isSkinned) { } 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..."; qDebug() << "unexpected!!! we don't know which list of meshes to render...";
return 0; return 0;
} }
QList<int>& list = *whichList; QVector<int>& list = *whichList;
ProgramObject* program = &_program; ProgramObject* program = &_program;
Locations* locations = &_locations; Locations* locations = &_locations;
@ -1486,6 +1486,14 @@ int Model::renderMeshes(RenderMode mode, bool translucent, float alphaThreshold,
// i is the "index" from the original networkMeshes QVector... // i is the "index" from the original networkMeshes QVector...
foreach (int i, list) { 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 // exit early if the translucency doesn't match what we're drawing
const NetworkMesh& networkMesh = networkMeshes.at(i); const NetworkMesh& networkMesh = networkMeshes.at(i);

View file

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