Bugfix : Replaced ugly (const_)casting by a better ctor and placement new. ( merged from GitHub, thanks to Riku Palomäki ).

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1217 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/5/head
kimmi 2012-03-20 20:45:33 +00:00
parent cb71e6f5f2
commit 42def11d13
2 changed files with 8 additions and 4 deletions

View File

@ -116,6 +116,10 @@ struct Surface
uint32_t ulOffsetFrameBaseFrames ; uint32_t ulOffsetFrameBaseFrames ;
uint32_t ulOffsetFrameCompFrames ; uint32_t ulOffsetFrameCompFrames ;
uint32_t ulOffsetEnd; uint32_t ulOffsetEnd;
Surface()
{
ucName[AI_MDC_MAXQPATH-1] = '\0';
}
} PACK_STRUCT; } PACK_STRUCT;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -230,7 +230,7 @@ void MDCImporter::InternReadFile(
// get the number of valid surfaces // get the number of valid surfaces
BE_NCONST MDC::Surface* pcSurface, *pcSurface2; BE_NCONST MDC::Surface* pcSurface, *pcSurface2;
pcSurface = pcSurface2 = (BE_NCONST MDC::Surface*)(mBuffer + pcHeader->ulOffsetSurfaces); pcSurface = pcSurface2 = new (mBuffer + pcHeader->ulOffsetSurfaces) MDC::Surface;
unsigned int iNumShaders = 0; unsigned int iNumShaders = 0;
for (unsigned int i = 0; i < pcHeader->ulNumSurfaces;++i) for (unsigned int i = 0; i < pcHeader->ulNumSurfaces;++i)
{ {
@ -239,7 +239,7 @@ void MDCImporter::InternReadFile(
if (pcSurface2->ulNumVertices && pcSurface2->ulNumTriangles)++pScene->mNumMeshes; if (pcSurface2->ulNumVertices && pcSurface2->ulNumTriangles)++pScene->mNumMeshes;
iNumShaders += pcSurface2->ulNumShaders; iNumShaders += pcSurface2->ulNumShaders;
pcSurface2 = (BE_NCONST MDC::Surface*)((int8_t*)pcSurface2 + pcSurface2->ulOffsetEnd); pcSurface2 = new ((int8_t*)pcSurface2 + pcSurface2->ulOffsetEnd) MDC::Surface;
} }
aszShaders.reserve(iNumShaders); aszShaders.reserve(iNumShaders);
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
@ -399,7 +399,7 @@ void MDCImporter::InternReadFile(
pcFaceCur->mIndices[2] = iOutIndex + 0; pcFaceCur->mIndices[2] = iOutIndex + 0;
} }
pcSurface = (BE_NCONST MDC::Surface*)((int8_t*)pcSurface + pcSurface->ulOffsetEnd); pcSurface = new ((int8_t*)pcSurface + pcSurface->ulOffsetEnd) MDC::Surface;
} }
// create a flat node graph with a root node and one child for each surface // create a flat node graph with a root node and one child for each surface