Skip to content

Commit

Permalink
[obj2c] Explicitly initialize "empty" arrays with 0s
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Oct 2, 2024
1 parent 3c6e841 commit 3e568c3
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tools/obj2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void generate_code(FILE *out, Vertices vertices, TexCoords texcoords, Normals no
fprintf(out, "#define OBJ_H_\n");
fprintf(out, "#define vertices_count %zu\n", vertices.count);
if (vertices.count == 0) {
fprintf(out, "static const float vertices[1][3];\n");
fprintf(out, "static const float vertices[1][3] = {0};\n");
} else {
fprintf(out, "static const float vertices[][3] = {\n");
for (size_t i = 0; i < vertices.count; ++i) {
Expand All @@ -214,7 +214,7 @@ void generate_code(FILE *out, Vertices vertices, TexCoords texcoords, Normals no

fprintf(out, "#define texcoords_count %zu\n", texcoords.count);
if (texcoords.count == 0) {
fprintf(out, "static const float texcoords[1][3];\n");
fprintf(out, "static const float texcoords[1][3] = {0};\n");
} else {
fprintf(out, "static const float texcoords[][3] = {\n");
for (size_t i = 0; i < texcoords.count; ++i) {
Expand All @@ -226,7 +226,7 @@ void generate_code(FILE *out, Vertices vertices, TexCoords texcoords, Normals no

fprintf(out, "#define normals_count %zu\n", normals.count);
if (normals.count == 0) {
fprintf(out, "static const float normals[1][3];\n");
fprintf(out, "static const float normals[1][3] = {0};\n");
} else {
fprintf(out, "static const float normals[][3] = {\n");
for (size_t i = 0; i < normals.count; ++i) {
Expand All @@ -245,7 +245,7 @@ void generate_code(FILE *out, Vertices vertices, TexCoords texcoords, Normals no

fprintf(out, "#define faces_count %zu\n", visible_faces_count);
if (visible_faces_count == 0) {
fprintf(out, "static const int faces[1][9];\n");
fprintf(out, "static const int faces[1][9] = {0};\n");
} else {
fprintf(out, "static const int faces[%zu][9] = {\n", visible_faces_count);
for (size_t i = 0; i < faces.count; ++i) {
Expand Down
Binary file modified wasm/cup3d.wasm
Binary file not shown.
Binary file modified wasm/dots3d.wasm
Binary file not shown.
Binary file modified wasm/penger3d.wasm
Binary file not shown.
Binary file modified wasm/squish.wasm
Binary file not shown.
Binary file modified wasm/teapot3d.wasm
Binary file not shown.
Binary file modified wasm/triangle.wasm
Binary file not shown.
Binary file modified wasm/triangle3d.wasm
Binary file not shown.
Binary file modified wasm/triangle3dTex.wasm
Binary file not shown.
Binary file modified wasm/triangleTex.wasm
Binary file not shown.

0 comments on commit 3e568c3

Please sign in to comment.