MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / safeSwapPtr

Method safeSwapPtr

src/Bullet3Serialize/Bullet2FileLoader/b3File.cpp:852–905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

850}
851
852void bFile::safeSwapPtr(char *dst, const char *src)
853{
854 if (!src || !dst)
855 return;
856
857 int ptrFile = mFileDNA->getPointerSize();
858 int ptrMem = mMemoryDNA->getPointerSize();
859
860 if (ptrFile == ptrMem)
861 {
862 memcpy(dst, src, ptrMem);
863 }
864 else if (ptrMem == 4 && ptrFile == 8)
865 {
866 b3PointerUid *oldPtr = (b3PointerUid *)src;
867 b3PointerUid *newPtr = (b3PointerUid *)dst;
868
869 if (oldPtr->m_uniqueIds[0] == oldPtr->m_uniqueIds[1])
870 {
871 //Bullet stores the 32bit unique ID in both upper and lower part of 64bit pointers
872 //so it can be used to distinguish between .blend and .bullet
873 newPtr->m_uniqueIds[0] = oldPtr->m_uniqueIds[0];
874 }
875 else
876 {
877 //deal with pointers the Blender .blend style way, see
878 //readfile.c in the Blender source tree
879 b3Long64 longValue = *((b3Long64 *)src);
880 //endian swap for 64bit pointer otherwise truncation will fail due to trailing zeros
881 if (mFlags & FD_ENDIAN_SWAP)
882 B3_SWITCH_LONGINT(longValue);
883 *((int *)dst) = (int)(longValue >> 3);
884 }
885 }
886 else if (ptrMem == 8 && ptrFile == 4)
887 {
888 b3PointerUid *oldPtr = (b3PointerUid *)src;
889 b3PointerUid *newPtr = (b3PointerUid *)dst;
890 if (oldPtr->m_uniqueIds[0] == oldPtr->m_uniqueIds[1])
891 {
892 newPtr->m_uniqueIds[0] = oldPtr->m_uniqueIds[0];
893 newPtr->m_uniqueIds[1] = 0;
894 }
895 else
896 {
897 *((b3Long64 *)dst) = *((int *)src);
898 }
899 }
900 else
901 {
902 printf("%d %d\n", ptrFile, ptrMem);
903 assert(0 && "Invalid pointer len");
904 }
905}
906
907// ----------------------------------------------------- //
908void bFile::getMatchingFileDNA(short *dna_addr, const char *lookupName, const char *lookupType, char *strcData, char *data, bool fixupPointers)

Callers

nothing calls this directly

Calls 1

getPointerSizeMethod · 0.45

Tested by

no test coverage detected