Fixed some serialization issues related to swapping endianness of DNA, and fixed memory leak in btSerializer
This commit is contained in:
@@ -16,6 +16,10 @@ subject to the following restrictions:
|
|||||||
#include "btBulletFile.h"
|
#include "btBulletFile.h"
|
||||||
#include "bDefines.h"
|
#include "bDefines.h"
|
||||||
#include "bDNA.h"
|
#include "bDNA.h"
|
||||||
|
|
||||||
|
#if !defined( __CELLOS_LV2__) && !defined(__MWERKS__)
|
||||||
|
#include <memory.h>
|
||||||
|
#endif
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -43,18 +47,32 @@ btBulletFile::btBulletFile()
|
|||||||
:bFile("", "BULLET ")
|
:bFile("", "BULLET ")
|
||||||
{
|
{
|
||||||
mMemoryDNA = new bDNA();
|
mMemoryDNA = new bDNA();
|
||||||
|
m_DnaCopy = 0;
|
||||||
|
|
||||||
|
|
||||||
#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
mMemoryDNA->init((char*)sBulletDNAstr64,sBulletDNAlen64);
|
m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64,16);
|
||||||
|
memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64);
|
||||||
|
mMemoryDNA->init(m_DnaCopy,sBulletDNAlen64);
|
||||||
#else//_WIN64
|
#else//_WIN64
|
||||||
mMemoryDNA->init((char*)sBulletDNAstr,sBulletDNAlen);
|
m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen,16);
|
||||||
|
memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen);
|
||||||
|
mMemoryDNA->init(m_DnaCopy,sBulletDNAlen);
|
||||||
#endif//_WIN64
|
#endif//_WIN64
|
||||||
#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
||||||
if (VOID_IS_8)
|
if (VOID_IS_8)
|
||||||
mMemoryDNA->init((char*)sBulletDNAstr64,sBulletDNAlen64);
|
{
|
||||||
else
|
m_DnaCopy = (char*) btAlignedAlloc(sBulletDNAlen64,16);
|
||||||
mMemoryDNA->init((char*)sBulletDNAstr,sBulletDNAlen);
|
memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64);
|
||||||
|
mMemoryDNA->init(m_DnaCopy,sBulletDNAlen64);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_DnaCopy =(char*) btAlignedAlloc(sBulletDNAlen,16);
|
||||||
|
memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen);
|
||||||
|
mMemoryDNA->init(m_DnaCopy,sBulletDNAlen);
|
||||||
|
}
|
||||||
#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +81,7 @@ btBulletFile::btBulletFile()
|
|||||||
btBulletFile::btBulletFile(const char* fileName)
|
btBulletFile::btBulletFile(const char* fileName)
|
||||||
:bFile(fileName, "BULLET ")
|
:bFile(fileName, "BULLET ")
|
||||||
{
|
{
|
||||||
|
m_DnaCopy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -70,13 +89,14 @@ btBulletFile::btBulletFile(const char* fileName)
|
|||||||
btBulletFile::btBulletFile(char *memoryBuffer, int len)
|
btBulletFile::btBulletFile(char *memoryBuffer, int len)
|
||||||
:bFile(memoryBuffer,len, "BULLET ")
|
:bFile(memoryBuffer,len, "BULLET ")
|
||||||
{
|
{
|
||||||
|
m_DnaCopy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
btBulletFile::~btBulletFile()
|
btBulletFile::~btBulletFile()
|
||||||
{
|
{
|
||||||
|
if (m_DnaCopy)
|
||||||
|
btAlignedFree(m_DnaCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -234,6 +254,12 @@ void btBulletFile::parse(bool verboseDumpAllTypes)
|
|||||||
if (VOID_IS_8)
|
if (VOID_IS_8)
|
||||||
{
|
{
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
|
|
||||||
|
if (m_DnaCopy)
|
||||||
|
delete m_DnaCopy;
|
||||||
|
m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64,16);
|
||||||
|
memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64);
|
||||||
|
mMemoryDNA->init(m_DnaCopy,sBulletDNAlen64);
|
||||||
parseInternal(verboseDumpAllTypes,(char*)sBulletDNAstr64,sBulletDNAlen64);
|
parseInternal(verboseDumpAllTypes,(char*)sBulletDNAstr64,sBulletDNAlen64);
|
||||||
#else
|
#else
|
||||||
btAssert(0);
|
btAssert(0);
|
||||||
@@ -242,7 +268,13 @@ void btBulletFile::parse(bool verboseDumpAllTypes)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifndef _WIN64
|
#ifndef _WIN64
|
||||||
parseInternal(verboseDumpAllTypes,(char*)sBulletDNAstr,sBulletDNAlen);
|
|
||||||
|
if (m_DnaCopy)
|
||||||
|
delete m_DnaCopy;
|
||||||
|
m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen,16);
|
||||||
|
memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen);
|
||||||
|
mMemoryDNA->init(m_DnaCopy,sBulletDNAlen);
|
||||||
|
parseInternal(verboseDumpAllTypes,m_DnaCopy,sBulletDNAlen);
|
||||||
#else
|
#else
|
||||||
btAssert(0);
|
btAssert(0);
|
||||||
#endif
|
#endif
|
||||||
@@ -250,11 +282,19 @@ void btBulletFile::parse(bool verboseDumpAllTypes)
|
|||||||
#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
||||||
if (VOID_IS_8)
|
if (VOID_IS_8)
|
||||||
{
|
{
|
||||||
parseInternal(verboseDumpAllTypes,(char*)sBulletDNAstr64,sBulletDNAlen64);
|
if (m_DnaCopy)
|
||||||
|
delete m_DnaCopy;
|
||||||
|
m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64,16);
|
||||||
|
memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64);
|
||||||
|
parseInternal(verboseDumpAllTypes,m_DnaCopy,sBulletDNAlen64);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
parseInternal(verboseDumpAllTypes,(char*)sBulletDNAstr,sBulletDNAlen);
|
if (m_DnaCopy)
|
||||||
|
delete m_DnaCopy;
|
||||||
|
m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen,16);
|
||||||
|
memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen);
|
||||||
|
parseInternal(verboseDumpAllTypes,m_DnaCopy,sBulletDNAlen);
|
||||||
}
|
}
|
||||||
#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ namespace bParse {
|
|||||||
class btBulletFile : public bFile
|
class btBulletFile : public bFile
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
char* m_DnaCopy;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -125,6 +125,9 @@ class btDefaultSerializer : public btSerializer
|
|||||||
int m_totalSize;
|
int m_totalSize;
|
||||||
unsigned char* m_buffer;
|
unsigned char* m_buffer;
|
||||||
int m_currentSize;
|
int m_currentSize;
|
||||||
|
void* m_dna;
|
||||||
|
int m_dnaLength;
|
||||||
|
|
||||||
|
|
||||||
btAlignedObjectArray<btChunk*> m_chunkPtrs;
|
btAlignedObjectArray<btChunk*> m_chunkPtrs;
|
||||||
|
|
||||||
@@ -333,8 +336,6 @@ protected:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
void* m_dna;
|
|
||||||
int m_dnaLength;
|
|
||||||
|
|
||||||
|
|
||||||
btDefaultSerializer(int totalSize)
|
btDefaultSerializer(int totalSize)
|
||||||
@@ -378,7 +379,10 @@ public:
|
|||||||
|
|
||||||
virtual ~btDefaultSerializer()
|
virtual ~btDefaultSerializer()
|
||||||
{
|
{
|
||||||
btAlignedFree(m_buffer);
|
if (m_buffer)
|
||||||
|
btAlignedFree(m_buffer);
|
||||||
|
if (m_dna)
|
||||||
|
btAlignedFree(m_dna);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void startSerialization()
|
virtual void startSerialization()
|
||||||
|
|||||||
Reference in New Issue
Block a user