Skip to content

Commit c2f4364

Browse files
authored
Merge pull request #22 from musicinmybrain/ctm-export-empty
Fix out-of-bounds access when exporting an empty mesh to CTM (fix #21)
2 parents 58d14c7 + 7439118 commit c2f4364

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tools/ctm.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,16 @@ void Export_CTM(const char * aFileName, Mesh * aMesh, Options &aOptions)
123123
CTMfloat * normals = 0;
124124
if(aMesh->HasNormals() && !aOptions.mNoNormals)
125125
normals = &aMesh->mNormals[0].x;
126-
ctm.DefineMesh((CTMfloat *) &aMesh->mVertices[0].x, aMesh->mVertices.size(),
127-
(const CTMuint*) &aMesh->mIndices[0], aMesh->mIndices.size() / 3,
126+
CTMfloat dummy_vertex = 0;
127+
CTMfloat * vertices = &dummy_vertex;
128+
if(aMesh->mVertices.size()>0)
129+
vertices = (CTMfloat *) &aMesh->mVertices[0].x;
130+
CTMuint dummy_index = 0;
131+
const CTMuint * indices = &dummy_index;
132+
if(aMesh->mIndices.size()>0)
133+
indices = (const CTMuint*) &aMesh->mIndices[0];
134+
ctm.DefineMesh(vertices, aMesh->mVertices.size(),
135+
indices, aMesh->mIndices.size() / 3,
128136
normals);
129137

130138
// Define texture coordinates

0 commit comments

Comments
 (0)