From 65dbac28f02f46bd7add402153b0cd7e070d5895 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 2 Sep 2015 09:00:00 +0200 Subject: [PATCH] Change array serialisation functions to explicitly be uint32/uint64. --- renderdoc/serialise/serialiser.h | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/renderdoc/serialise/serialiser.h b/renderdoc/serialise/serialiser.h index 9c29b4b8f..6178ce4a4 100644 --- a/renderdoc/serialise/serialiser.h +++ b/renderdoc/serialise/serialiser.h @@ -341,7 +341,7 @@ class Serialiser template void SerialisePODArray(const char *name, T *el) { - size_t n = Num; + uint32_t n = (uint32_t)Num; SerialisePODArray(name, el, n); } @@ -351,10 +351,8 @@ class Serialiser // If serialising in, el must either be NULL in which case allocated // memory will be returned, or it must be already large enough. template - void SerialisePODArray(const char *name, T *&el, size_t &Num) + void SerialisePODArray(const char *name, T *&el, uint32_t &numElems) { - uint32_t numElems = (uint32_t)Num; - if(m_Mode == WRITING) { WriteFrom(numElems); @@ -373,16 +371,26 @@ class Serialiser memcpy(el, ReadBytes(length), length); } } - - Num = (size_t)numElems; if(name != NULL && m_DebugTextWriting) { - for(size_t i=0; i < Num; i++) + if(numElems == 0) + DebugPrint("%s[0]", name); + + for(size_t i=0; i < numElems; i++) DebugPrint("%s[%d] = %s\n", name, i, ToStr::Get(el[i]).c_str()); } } + // overload for 64-bit counts + template + void SerialisePODArray(const char *name, T *&el, uint64_t &Num) + { + uint32_t n = (uint32_t)Num; + SerialisePODArray(name, el, n); + Num = n; + } + // serialise a normal array. Typically this should be a small array, // for large byte buffers use SerialiseBuffer which is optimised for that // @@ -401,8 +409,6 @@ class Serialiser { ReadInto(Num); - RDCASSERT(el == NULL); - if(Num > 0) { el = new T[Num]; @@ -415,13 +421,16 @@ class Serialiser el = NULL; } } + + if(name != NULL && m_DebugTextWriting && Num == 0) + DebugPrint("%s[0]", name); } // overload for 64-bit counts template void SerialiseComplexArray(const char *name, T *&el, uint64_t &Num) { - uint32_t n; + uint32_t n = (uint32_t)Num; SerialiseComplexArray(name, el, n); Num = n; }