Skip to content

Commit

Permalink
Fix calculation for aligning next serialised buffer. Refs #133
Browse files Browse the repository at this point in the history
  • Loading branch information
baldurk committed Apr 28, 2015
1 parent c58c406 commit 3dac5fe
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions renderdoc/serialise/serialiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,23 +951,34 @@ void Serialiser::AlignNextBuffer(const size_t alignment)
// Note the chunk still needs to be aligned when the memory is allocated - this just ensures
// the offset from the start is also aligned

size_t len = 0;
uint32_t len = 0;

if(m_Mode >= WRITING)
{
// add sizeof(uint32_t) since we'll be serialising out how much padding is here
uint64_t curoffs = GetOffset() + sizeof(uint32_t);
// add sizeof(uint32_t) since we'll be serialising out how much padding is here,
// then another sizeof(uint32_t) so we're aligning the offset after the buffer's
// serialised length
uint64_t curoffs = GetOffset() + sizeof(uint32_t)*2;
uint64_t alignedoffs = AlignUp(curoffs, (uint64_t)alignment);

len = size_t(alignedoffs - curoffs);
len = uint32_t(alignedoffs - curoffs);
}

// avoid dynamically allocating
RDCASSERT(alignment <= 128);
byte padding[128] = {0};
byte *p = &padding[0];

SerialiseBuffer("", p, len);
if(m_Mode >= WRITING)
{
WriteFrom(len);
WriteBytes(&padding[0], (size_t)len);
}
else
{
ReadInto(len);
ReadBytes(len);
}
}

void Serialiser::SerialiseBuffer(const char *name, byte *&buf, size_t &len)
Expand Down

0 comments on commit 3dac5fe

Please sign in to comment.