From 6ae42d2d722158cbe08425937a33f65bbf306b59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Tue, 3 Jan 2017 00:40:07 +0100 Subject: [PATCH] Fixed crashes due to trianglesNum having wrong type --- Source/Graphic/Models.cpp | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Source/Graphic/Models.cpp b/Source/Graphic/Models.cpp index 78970d5..0f6a2db 100644 --- a/Source/Graphic/Models.cpp +++ b/Source/Graphic/Models.cpp @@ -395,7 +395,7 @@ bool Model::loadnotex(const std::string& filename) { FILE *tfile; long i; - int TriangleNum; + short triangleNum; type = notextype; color = 0; @@ -405,7 +405,7 @@ bool Model::loadnotex(const std::string& filename) // read model settings fseek(tfile, 0, SEEK_SET); - funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum); + funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum); // read the model data deallocate(); @@ -414,14 +414,14 @@ bool Model::loadnotex(const std::string& filename) owner = (int*)malloc(sizeof(int) * vertexNum); vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum); - Triangles.resize(TriangleNum); - vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24); + Triangles.resize(triangleNum); + vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24); for (i = 0; i < vertexNum; i++) { funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z); } - for (i = 0; i < TriangleNum; i++) { + for (i = 0; i < triangleNum; i++) { short vertex[6]; funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]); Triangles[i].vertex[0] = vertex[0]; @@ -458,7 +458,7 @@ bool Model::load(const std::string& filename) { FILE *tfile; long i; - int TriangleNum; + short triangleNum; LOGFUNC; @@ -474,7 +474,7 @@ bool Model::load(const std::string& filename) // read model settings fseek(tfile, 0, SEEK_SET); - funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum); + funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum); // read the model data deallocate(); @@ -484,14 +484,14 @@ bool Model::load(const std::string& filename) owner = (int*)malloc(sizeof(int) * vertexNum); vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum); normals = (XYZ*)malloc(sizeof(XYZ) * vertexNum); - Triangles.resize(TriangleNum); - vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24); + Triangles.resize(triangleNum); + vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24); for (i = 0; i < vertexNum; i++) { funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z); } - for (i = 0; i < TriangleNum; i++) { + for (i = 0; i < triangleNum; i++) { short vertex[6]; funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]); Triangles[i].vertex[0] = vertex[0]; @@ -530,7 +530,7 @@ bool Model::loaddecal(const std::string& filename) { FILE *tfile; long i, j; - int TriangleNum; + short triangleNum; LOGFUNC; @@ -545,7 +545,7 @@ bool Model::loaddecal(const std::string& filename) // read model settings fseek(tfile, 0, SEEK_SET); - funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum); + funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum); // read the model data @@ -556,14 +556,14 @@ bool Model::loaddecal(const std::string& filename) owner = (int*)malloc(sizeof(int) * vertexNum); vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum); normals = (XYZ*)malloc(sizeof(XYZ) * vertexNum); - Triangles.resize(TriangleNum); - vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24); + Triangles.resize(triangleNum); + vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24); for (i = 0; i < vertexNum; i++) { funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z); } - for (i = 0; i < TriangleNum; i++) { + for (i = 0; i < triangleNum; i++) { short vertex[6]; funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]); Triangles[i].vertex[0] = vertex[0]; @@ -602,7 +602,7 @@ bool Model::loadraw(const std::string& filename) { FILE *tfile; long i; - int TriangleNum; + short triangleNum; LOGFUNC; @@ -616,7 +616,7 @@ bool Model::loadraw(const std::string& filename) // read model settings fseek(tfile, 0, SEEK_SET); - funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum); + funpackf(tfile, "Bs Bs", &vertexNum, &triangleNum); // read the model data deallocate(); @@ -625,15 +625,15 @@ bool Model::loadraw(const std::string& filename) owner = (int*)malloc(sizeof(int) * vertexNum); vertex = (XYZ*)malloc(sizeof(XYZ) * vertexNum); - Triangles.resize(TriangleNum); - vArray = (GLfloat*)malloc(sizeof(GLfloat) * TriangleNum * 24); + Triangles.resize(triangleNum); + vArray = (GLfloat*)malloc(sizeof(GLfloat) * triangleNum * 24); for (i = 0; i < vertexNum; i++) { funpackf(tfile, "Bf Bf Bf", &vertex[i].x, &vertex[i].y, &vertex[i].z); } - for (i = 0; i < TriangleNum; i++) { + for (i = 0; i < triangleNum; i++) { short vertex[6]; funpackf(tfile, "Bs Bs Bs Bs Bs Bs", &vertex[0], &vertex[1], &vertex[2], &vertex[3], &vertex[4], &vertex[5]); Triangles[i].vertex[0] = vertex[0]; -- 2.39.5