MeshSerializerImpl::calcGeometrySize returns incorrect value

Description

Original reporter: rride

Look at these methods implementation:

size_t MeshSerializerImpl::calcGeometrySize(const VertexData* vertexData){
size_t size = MSTREAM_OVERHEAD_SIZE;
// Num vertices
size += sizeof(unsigned int);

const VertexDeclaration::VertexElementList& elems = vertexData->vertexDeclaration->getElements();

VertexDeclaration::VertexElementList::const_iterator i, iend;
iend = elems.end();
for (i = elems.begin(); i != iend; ++i){
const VertexElement& elem = *i;
// Vertex element
size += VertexElement::getTypeSize(elem.getType()) * vertexData->vertexCount;
}
return size;
}

and

void MeshSerializerImpl::readGeometry(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest) {
dest->vertexStart = 0;

unsigned int vertexCount = 0;
readInts(stream, &vertexCount, 1);
dest->vertexCount = vertexCount;

// Find optional geometry streams
if (!stream->eof()){
unsigned short streamID = readChunk(stream);
while(!stream->eof() &&
(streamID == M_GEOMETRY_VERTEX_DECLARATION || streamID == M_GEOMETRY_VERTEX_BUFFER )){
switch (streamID){
case M_GEOMETRY_VERTEX_DECLARATION:
readGeometryVertexDeclaration(stream, pMesh, dest);
break;
case M_GEOMETRY_VERTEX_BUFFER:
readGeometryVertexBuffer(stream, pMesh, dest);
break;
}
// Get next stream
if (!stream->eof())
streamID = readChunk(stream);
}
if (!stream->eof())
// Backpedal back to start of non-submesh stream
stream->skip(-MSTREAM_OVERHEAD_SIZE);
}
// ... bla-bla-bla
}

As we see readGeometry() method reads both vertex declarations and vertex buffers from '.mesh' file while calcGeometrySize() returns value as if it were reading only vertex data without any declarations. Additionally sizes of chunk headers M_GEOMETRY_VERTEX_DECLARATION and M_GEOMETRY_VERTEX_BUFFER should also be added to total size.

Original Mantis Ticket: http://www.ogre3d.org/mantis/view.php?id=486

Environment

None

Assignee

M

Reporter

Philip Allgaier

Labels

None

Components

Fix versions

Affects versions

Priority

Blocker
Configure