Permalink
Browse files

fixing stuff

  • Loading branch information...
jamesgao committed Feb 7, 2013
1 parent c0d6a6c commit baf570b0f9da7b0b4f8588e04ae86a416891a682
View
@@ -45,12 +45,12 @@
// _ctmFreeMapList() - Free a float map list.
//-----------------------------------------------------------------------------
static void _ctmFreeMapList(_CTMcontext * self, _CTMfloatmap * aMapList)
-{
- _CTMfloatmap * map, * nextMap;
+{
+ _CTMfloatmap * map, * nextMap;

This comment has been minimized.

Show comment
Hide comment
@yarikoptic

yarikoptic Nov 18, 2013

Contributor

just a comment for anyone reviewing this commit later -- there were no functional changes to openctm.c besides addition of printf statements

@yarikoptic

yarikoptic Nov 18, 2013

Contributor

just a comment for anyone reviewing this commit later -- there were no functional changes to openctm.c besides addition of printf statements

This comment has been minimized.

Show comment
Hide comment
@jamesgao

jamesgao Nov 18, 2013

Contributor

Oops, didn't actually mean to change the OpenCTM distribution at all. However, those printf statements are quite useful when OpenCTM just spits out a generic error message...

@jamesgao

jamesgao Nov 18, 2013

Contributor

Oops, didn't actually mean to change the OpenCTM distribution at all. However, those printf statements are quite useful when OpenCTM just spits out a generic error message...

map = aMapList;
- while(map)
+ while(map)
{
- // Free internally allocated array (if we are in import mode)
+ // Free internally allocated array (if we are in import mode)
if((self->mMode == CTM_IMPORT) && map->mValues)
free(map->mValues);
@@ -62,12 +62,12 @@ static void _ctmFreeMapList(_CTMcontext * self, _CTMfloatmap * aMapList)
if(map->mFileName)
free(map->mFileName);
- nextMap = map->mNext;
+ nextMap = map->mNext;
free(map);
- map = nextMap;
+ map = nextMap;
}
-}
-
+}
+
//-----------------------------------------------------------------------------
// _ctmClearMesh() - Clear the mesh in a CTM context.
//-----------------------------------------------------------------------------
@@ -83,23 +83,23 @@ static void _ctmClearMesh(_CTMcontext * self)
if(self->mNormals)
free(self->mNormals);
}
-
+
// Clear externally assigned mesh arrays
self->mVertices = (CTMfloat *) 0;
self->mVertexCount = 0;
self->mIndices = (CTMuint *) 0;
- self->mTriangleCount = 0;
- self->mNormals = (CTMfloat *) 0;
-
- // Free UV coordinate map list
- _ctmFreeMapList(self, self->mUVMaps);
- self->mUVMaps = (_CTMfloatmap *) 0;
- self->mUVMapCount = 0;
-
- // Free attribute map list
- _ctmFreeMapList(self, self->mAttribMaps);
- self->mAttribMaps = (_CTMfloatmap *) 0;
- self->mAttribMapCount = 0;
+ self->mTriangleCount = 0;
+ self->mNormals = (CTMfloat *) 0;
+
+ // Free UV coordinate map list
+ _ctmFreeMapList(self, self->mUVMaps);
+ self->mUVMaps = (_CTMfloatmap *) 0;
+ self->mUVMapCount = 0;
+
+ // Free attribute map list
+ _ctmFreeMapList(self, self->mAttribMaps);
+ self->mAttribMaps = (_CTMfloatmap *) 0;
+ self->mAttribMapCount = 0;
}
//-----------------------------------------------------------------------------
@@ -116,6 +116,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
if(!self->mVertices || !self->mIndices || (self->mVertexCount < 1) ||
(self->mTriangleCount < 1))
{
+ printf("Error in vertex count\n");
return CTM_FALSE;
}
@@ -124,6 +125,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
{
if(self->mIndices[i] >= self->mVertexCount)
{
+ printf("Index not in vertex length\n");
return CTM_FALSE;
}
}
@@ -133,6 +135,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
{
if(!isfinite(self->mVertices[i]))
{
+ printf("Vertex is NaN or Inf\n");
return CTM_FALSE;
}
}
@@ -157,6 +160,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
{
if(!isfinite(map->mValues[i]))
{
+ printf("UVs are NaN or Inf\n");
return CTM_FALSE;
}
}
@@ -171,6 +175,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
{
if(!isfinite(map->mValues[i]))
{
+ printf("Attribute %s is NaN or Inf at %d\n", map->mName, i);
return CTM_FALSE;
}
}
@@ -210,12 +215,12 @@ CTMEXPORT void CTMCALL ctmFreeContext(CTMcontext aContext)
_CTMcontext * self = (_CTMcontext *) aContext;
if(!self) return;
- // Free all mesh resources
+ // Free all mesh resources
_ctmClearMesh(self);
- // Free the file comment
+ // Free the file comment
if(self->mFileComment)
- free(self->mFileComment);
+ free(self->mFileComment);
// Free the context
free(self);
@@ -354,48 +359,48 @@ CTMEXPORT const CTMuint * CTMCALL ctmGetIntegerArray(CTMcontext aContext,
CTMEXPORT const CTMfloat * CTMCALL ctmGetFloatArray(CTMcontext aContext,
CTMenum aProperty)
{
- _CTMcontext * self = (_CTMcontext *) aContext;
- _CTMfloatmap * map;
+ _CTMcontext * self = (_CTMcontext *) aContext;
+ _CTMfloatmap * map;
CTMuint i;
if(!self) return (CTMfloat *) 0;
-
- // Did the user request a UV map?
- if((aProperty >= CTM_UV_MAP_1) &&
- ((CTMuint)(aProperty - CTM_UV_MAP_1) < self->mUVMapCount))
- {
- map = self->mUVMaps;
- i = CTM_UV_MAP_1;
- while(map && (i != aProperty))
- {
- map = map->mNext;
- ++ i;
- }
- if(!map)
- {
- self->mError = CTM_INTERNAL_ERROR;
+
+ // Did the user request a UV map?
+ if((aProperty >= CTM_UV_MAP_1) &&
+ ((CTMuint)(aProperty - CTM_UV_MAP_1) < self->mUVMapCount))
+ {
+ map = self->mUVMaps;
+ i = CTM_UV_MAP_1;
+ while(map && (i != aProperty))
+ {
+ map = map->mNext;
+ ++ i;
+ }
+ if(!map)
+ {
+ self->mError = CTM_INTERNAL_ERROR;
return (CTMfloat *) 0;
- }
+ }
return map->mValues;
- }
-
- // Did the user request an attribute map?
- if((aProperty >= CTM_ATTRIB_MAP_1) &&
- ((CTMuint)(aProperty - CTM_ATTRIB_MAP_1) < self->mAttribMapCount))
- {
- map = self->mAttribMaps;
- i = CTM_ATTRIB_MAP_1;
- while(map && (i != aProperty))
- {
- map = map->mNext;
- ++ i;
- }
- if(!map)
- {
- self->mError = CTM_INTERNAL_ERROR;
+ }
+
+ // Did the user request an attribute map?
+ if((aProperty >= CTM_ATTRIB_MAP_1) &&
+ ((CTMuint)(aProperty - CTM_ATTRIB_MAP_1) < self->mAttribMapCount))
+ {
+ map = self->mAttribMaps;
+ i = CTM_ATTRIB_MAP_1;
+ while(map && (i != aProperty))
+ {
+ map = map->mNext;
+ ++ i;
+ }
+ if(!map)
+ {
+ self->mError = CTM_INTERNAL_ERROR;
return (CTMfloat *) 0;
- }
+ }
return map->mValues;
- }
+ }
switch(aProperty)
{
@@ -416,26 +421,26 @@ CTMEXPORT const CTMfloat * CTMCALL ctmGetFloatArray(CTMcontext aContext,
// ctmGetNamedUVMap()
//-----------------------------------------------------------------------------
CTMEXPORT CTMenum CTMCALL ctmGetNamedUVMap(CTMcontext aContext,
- const char * aName)
-{
+ const char * aName)
+{
_CTMcontext * self = (_CTMcontext *) aContext;
- _CTMfloatmap * map;
+ _CTMfloatmap * map;
CTMuint result;
if(!self) return CTM_NONE;
-
- map = self->mUVMaps;
- result = CTM_UV_MAP_1;
- while(map && (strcmp(aName, map->mName) != 0))
- {
- map = map->mNext;
- ++ result;
- }
- if(!map)
- {
+
+ map = self->mUVMaps;
+ result = CTM_UV_MAP_1;
+ while(map && (strcmp(aName, map->mName) != 0))
+ {
+ map = map->mNext;
+ ++ result;
+ }
+ if(!map)
+ {
return CTM_NONE;
- }
+ }
return result;
-}
+}
//-----------------------------------------------------------------------------
// ctmGetUVMapString()
@@ -596,27 +601,27 @@ CTMEXPORT CTMfloat CTMCALL ctmGetAttribMapFloat(CTMcontext aContext,
// ctmGetNamedAttribMap()
//-----------------------------------------------------------------------------
CTMEXPORT CTMenum CTMCALL ctmGetNamedAttribMap(CTMcontext aContext,
- const char * aName)
-{
+ const char * aName)
+{
_CTMcontext * self = (_CTMcontext *) aContext;
- _CTMfloatmap * map;
+ _CTMfloatmap * map;
CTMuint result;
if(!self) return CTM_NONE;
-
- map = self->mAttribMaps;
- result = CTM_ATTRIB_MAP_1;
- while(map && (strcmp(aName, map->mName) != 0))
- {
- map = map->mNext;
- ++ result;
- }
- if(!map)
- {
+
+ map = self->mAttribMaps;
+ result = CTM_ATTRIB_MAP_1;
+ while(map && (strcmp(aName, map->mName) != 0))
+ {
+ map = map->mNext;
+ ++ result;
+ }
+ if(!map)
+ {
return CTM_NONE;
- }
- return result;
-}
-
+ }
+ return result;
+}
+
//-----------------------------------------------------------------------------
// ctmGetString()
//-----------------------------------------------------------------------------
@@ -1059,7 +1064,7 @@ CTMEXPORT CTMenum CTMCALL ctmAddUVMap(CTMcontext aContext,
if(!map)
return CTM_NONE;
else
- {
+ {
// The default UV coordinate precision is 2^-12
map->mPrecision = 1.0f / 4096.0f;
++ self->mUVMapCount;
@@ -1152,7 +1157,7 @@ static CTMuint _ctmAllocateFloatMaps(_CTMcontext * self,
}
memset(*mapListPtr, 0, sizeof(_CTMfloatmap));
- // Allocate & clear memory for the float array
+ // Allocate & clear memory for the float array
size = aChannels * sizeof(CTMfloat) * self->mVertexCount;
(*mapListPtr)->mValues = (CTMfloat *) malloc(size);
if(!(*mapListPtr)->mValues)
Oops, something went wrong.

0 comments on commit baf570b

Please sign in to comment.