From 56f3df802ee8671b647bdfb28f7756fa418f3f1e Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Fri, 26 Feb 2010 03:07:23 +0000 Subject: [PATCH] update serialization mainly for Blender .blend reading, it has to do with pointer arrays not being swapped properly (Bullet .bullet doesn't use pointer arrays so it isn't affected) Thanks a lot to Charlie/snailrose for the fix --- Extras/Serialize/BulletFileLoader/bFile.cpp | 46 ++++++++++++++------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/Extras/Serialize/BulletFileLoader/bFile.cpp b/Extras/Serialize/BulletFileLoader/bFile.cpp index b41729256..79b349557 100644 --- a/Extras/Serialize/BulletFileLoader/bFile.cpp +++ b/Extras/Serialize/BulletFileLoader/bFile.cpp @@ -295,8 +295,9 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk) numallocs++; // numBlocks * length - char *dataAlloc = new char[(dataChunk.nr*curLen)+1]; - memset(dataAlloc, 0, (dataChunk.nr*curLen)+1); + int allocLen = curLen > oldLen ? curLen : oldLen; + char *dataAlloc = new char[(dataChunk.nr*allocLen)+1]; + memset(dataAlloc, 0, (dataChunk.nr*allocLen)+1); // track allocated addDataBlock(dataAlloc); @@ -552,8 +553,8 @@ void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const c if (name[0] == '*') { // cast pointers - //int ptrFile = mFileDNA->getPointerSize(); - //int ptrMem = mMemoryDNA->getPointerSize(); + int ptrFile = mFileDNA->getPointerSize(); + int ptrMem = mMemoryDNA->getPointerSize(); swapPtr(strcData, data); @@ -561,13 +562,19 @@ void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const c { if (arrayLen > 1) { - void **sarray = (void**)strcData; - void **darray = (void**)data; - + //void **sarray = (void**)strcData; + //void **darray = (void**)data; + + char *cpc, *cpo; + cpc = (char*)strcData; + cpo = (char*)data; + for (int a=0; agetPointerSize(); + int ptrFile = mFileDNA->getPointerSize(); + int n=0, n2=0; - int swapoffs = mFileDNA->getPointerSize() > mMemoryDNA->getPointerSize() ? 2 : 1; + int swapoffs = 2; void *np = array[n]; while(np) { - if (mFlags & FD_BITS_VARIES) + if (ptrMem > ptrFile) + { + swapPtr((char*)&array[n2], (char*)&array[n]); + np = findLibPointer(array[n2]); + } + else if (ptrMem < ptrFile) + { swapPtr((char*)&array[n], (char*)&array[n2]); - - np = findLibPointer(array[n]); + np = findLibPointer(array[n]); + } + else + np = findLibPointer(array[n]); + if (np) array[n] = np; ++n;