When exporting struct buffers we must always allocate memory to readback

* If the external code has a NULL pointer and doesn't want to allocate
  but we are exporting buffer data, we still need to read the data
  somewhere so make a temporary allocation to read it into.
This commit is contained in:
baldurk
2017-11-09 15:12:06 +00:00
parent 13f4ac481e
commit ebe1318f72
+19
View File
@@ -234,6 +234,8 @@ public:
obj.type.byteSize = byteSize;
}
byte *tempAlloc = NULL;
{
if(IsWriting())
{
@@ -261,6 +263,17 @@ public:
else
el = NULL;
}
// if we're exporting the buffers, make sure to always alloc space to read the data, so we
// can save it out, even if the external code has no use for it and has asked for no
// allocation.
if(el == NULL && ExportStructure() && m_ExportBuffers)
{
if(byteSize > 0)
el = tempAlloc = AllocAlignedBuffer(byteSize);
else
el = NULL;
}
#endif
m_Read->Read(el, byteSize);
@@ -286,6 +299,12 @@ public:
m_StructureStack.pop_back();
}
if(tempAlloc)
{
FreeAlignedBuffer(tempAlloc);
el = NULL;
}
return *this;
}