From ad357afc36077668aa55488a84753e6424c825cd Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sat, 7 Apr 2018 22:09:29 -0700 Subject: [PATCH] Initialized pointers for arrays in struct Batch --- include/devil1geo.h | 2 ++ src/devil1geo.c | 22 +++++++++++++++------- test/main.c | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/devil1geo.h b/include/devil1geo.h index f40f967..8bfb750 100644 --- a/include/devil1geo.h +++ b/include/devil1geo.h @@ -76,6 +76,8 @@ void printmeshbatch(struct Batch*); void printpositions(struct Positions*, unsigned int); +void printnormals(struct Normals*, unsigned int); + // ** = 'pass by reference' of a pointer to struct bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const); diff --git a/src/devil1geo.c b/src/devil1geo.c index 0ad4286..bfa9ce3 100644 --- a/src/devil1geo.c +++ b/src/devil1geo.c @@ -49,6 +49,16 @@ void printpositions(struct Positions *p, unsigned int count) { } } +void printnormals(struct Normals *n, unsigned int count) { + if (n == NULL) { + return; + } + unsigned int i; + for (i = 0; i < count; i++) { + printf("(%f, %f, %f)\n", (n[i]).x, (n[i]).y, (n[i]).z); + } +} + bool getmeshheader(struct MeshHeader **hs, unsigned int i, const char * const filedata) { @@ -75,13 +85,11 @@ bool getmeshbatch(struct Batch **b, } unsigned int offset = h -> offsetBatches; *b = (struct Batch*)(filedata + offset); - (*b) -> p = (struct Positions*)(filedata + ((*b) -> offsetPositions)); - printf("p = %x\n", (*b) -> offsetPositions); - printpositions((*b) -> p, 3); - (*b) -> n = NULL; - (*b) -> u = NULL; - (*b) -> bi = NULL; - (*b) -> bw = NULL; + (*b) -> p = (struct Positions*)(filedata + ((*b) -> offsetPositions)); + (*b) -> n = (struct Normals*)(filedata + ((*b) -> offsetNormals)); + (*b) -> u = (struct UVs*)(filedata + ((*b) -> offsetUVs)); + (*b) -> bi = (struct BoneIndexes*)(filedata + ((*b) -> offsetBoneIndexes)); + (*b) -> bw = (struct BoneWeights*)(filedata + ((*b) -> offsetBoneWeights)); done = true; return done; } diff --git a/test/main.c b/test/main.c index 0e80adf..9b28057 100644 --- a/test/main.c +++ b/test/main.c @@ -117,7 +117,7 @@ void extractmeshes(const char *filedata, unsigned int i; bool ok; //h -> numMesh - for (i = 0; i < 3; i++) { + for (i = 1; i < 2; i++) { ok = getmeshheader(&mh, i, filedata); if (ok) { getmeshbatch(&b, mh, filedata);