Commit 8ab9af9d authored by hybrid's avatar hybrid

Quick fix for partially read vertex data. I think we need to go away from c8 buffers someday.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@762 dfc29bdd-3216-0410-991c-e03cc46cb475
parent c2ec44c7
...@@ -63,7 +63,6 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -63,7 +63,6 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
return 0; return 0;
const u32 WORD_BUFFER_LENGTH = 512; const u32 WORD_BUFFER_LENGTH = 512;
c8 wordBuffer[WORD_BUFFER_LENGTH];
if (Mesh) if (Mesh)
Mesh->drop(); Mesh->drop();
...@@ -175,6 +174,8 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -175,6 +174,8 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
case 'f': // face case 'f': // face
{ {
const u32 FACE_BUFFER_LENGTH = 1024;
c8* wordBuffer = new c8[FACE_BUFFER_LENGTH];
c8 vertexWord[WORD_BUFFER_LENGTH]; // for retrieving vertex data c8 vertexWord[WORD_BUFFER_LENGTH]; // for retrieving vertex data
video::S3DVertex v; video::S3DVertex v;
u32 currentVertexCount = pCurrMtl->pMeshbuffer->Vertices.size(); u32 currentVertexCount = pCurrMtl->pMeshbuffer->Vertices.size();
...@@ -185,7 +186,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -185,7 +186,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
v.Color = pCurrMtl->pMeshbuffer->Material.DiffuseColor; v.Color = pCurrMtl->pMeshbuffer->Material.DiffuseColor;
// get all vertices data in this face (current line of obj file) // get all vertices data in this face (current line of obj file)
u32 length = copyLine(wordBuffer, pBufPtr, WORD_BUFFER_LENGTH, pBufEnd); u32 length = copyLine(&wordBuffer, pBufPtr, FACE_BUFFER_LENGTH, pBufEnd);
const c8* pLinePtr = wordBuffer; const c8* pLinePtr = wordBuffer;
const c8* const pEndPtr = wordBuffer+length; const c8* const pEndPtr = wordBuffer+length;
...@@ -233,8 +234,9 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -233,8 +234,9 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
pCurrMtl->pMeshbuffer->Indices.push_back( ( facePointCount - 2 - i ) + currentVertexCount ); pCurrMtl->pMeshbuffer->Indices.push_back( ( facePointCount - 2 - i ) + currentVertexCount );
pCurrMtl->pMeshbuffer->Indices.push_back( ( facePointCount - 3 - i ) + currentVertexCount ); pCurrMtl->pMeshbuffer->Indices.push_back( ( facePointCount - 3 - i ) + currentVertexCount );
} }
delete wordBuffer;
} }
break; break;
case '#': // comment case '#': // comment
default: default:
...@@ -376,7 +378,7 @@ void COBJMeshFileLoader::readMTL(const c8* pFileName, core::stringc relPath) ...@@ -376,7 +378,7 @@ void COBJMeshFileLoader::readMTL(const c8* pFileName, core::stringc relPath)
case 'm': // texture maps case 'm': // texture maps
if (pCurrMaterial) if (pCurrMaterial)
{ {
char type=0; // map_Kd - diffuse texture map u8 type=0; // map_Kd - diffuse texture map
if (!strncmp(pBufPtr,"map_bump",8)) if (!strncmp(pBufPtr,"map_bump",8))
type=1; type=1;
else if (!strncmp(pBufPtr,"map_d",5)) else if (!strncmp(pBufPtr,"map_d",5))
...@@ -697,7 +699,7 @@ u32 COBJMeshFileLoader::copyWord(c8* outBuf, const c8* const inBuf, u32 outBufLe ...@@ -697,7 +699,7 @@ u32 COBJMeshFileLoader::copyWord(c8* outBuf, const c8* const inBuf, u32 outBufLe
} }
u32 COBJMeshFileLoader::copyLine(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* pBufEnd) u32 COBJMeshFileLoader::copyLine(c8** outBuf, const c8* inBuf, u32 outBufLength, const c8* pBufEnd)
{ {
if (!outBufLength) if (!outBufLength)
return 0; return 0;
...@@ -715,12 +717,15 @@ u32 COBJMeshFileLoader::copyLine(c8* outBuf, const c8* inBuf, u32 outBufLength, ...@@ -715,12 +717,15 @@ u32 COBJMeshFileLoader::copyLine(c8* outBuf, const c8* inBuf, u32 outBufLength,
++i; ++i;
} }
u32 length = core::min_(i, outBufLength-1); if (i>outBufLength-1)
for (u32 j=0; j<length; ++j) {
outBuf[j] = inBuf[j]; delete [] *outBuf;
*outBuf = new c8[i+1];
}
memcpy(outBuf, inBuf, i);
outBuf[i] = 0; outBuf[i] = 0;
return length;
return i;
} }
......
...@@ -76,7 +76,7 @@ private: ...@@ -76,7 +76,7 @@ private:
// copies the current word from the inBuf to the outBuf // copies the current word from the inBuf to the outBuf
u32 copyWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd); u32 copyWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
// copies the current line from the inBuf to the outBuf // copies the current line from the inBuf to the outBuf
u32 copyLine(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd); u32 copyLine(c8** outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
// combination of goNextWord followed by copyWord // combination of goNextWord followed by copyWord
const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd); const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment