REVIEWED: vox_loader.h, 64bit issue #2186
This commit is contained in:
parent
72f3b00b00
commit
81240fe960
1 changed files with 30 additions and 25 deletions
55
src/external/vox_loader.h
vendored
55
src/external/vox_loader.h
vendored
|
@ -531,29 +531,34 @@ static void Vox_Build_Voxel(VoxArray3D* pvoxArray, int x, int y, int z, int matI
|
||||||
int Vox_LoadFromMemory(unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray)
|
int Vox_LoadFromMemory(unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray)
|
||||||
{
|
{
|
||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
//Read VOX file
|
// Read VOX file
|
||||||
//4 bytes: magic number ('V' 'O' 'X' 'space' )
|
// 4 bytes: magic number ('V' 'O' 'X' 'space')
|
||||||
//4 bytes: version number (current version is 150 )
|
// 4 bytes: version number (current version is 150)
|
||||||
|
|
||||||
unsigned long signature;
|
// @raysan5: Reviewed (unsigned long) -> (unsigned int), possible issue with Ubuntu 18.04 64bit
|
||||||
|
|
||||||
|
// @raysan5: reviewed signature loading
|
||||||
|
unsigned char signature[4] = { 0 };
|
||||||
|
|
||||||
unsigned char* fileData = pvoxData;
|
unsigned char* fileData = pvoxData;
|
||||||
|
|
||||||
unsigned char* fileDataPtr = fileData;
|
unsigned char* fileDataPtr = fileData;
|
||||||
unsigned char* endfileDataPtr = fileData + voxDataSize;
|
unsigned char* endfileDataPtr = fileData + voxDataSize;
|
||||||
|
|
||||||
signature = *((unsigned long *)fileDataPtr);
|
signature[0] = fileDataPtr[0];
|
||||||
fileDataPtr += sizeof(unsigned long);
|
signature[1] = fileDataPtr[1];
|
||||||
|
signature[2] = fileDataPtr[2];
|
||||||
|
signature[3] = fileDataPtr[3];
|
||||||
|
fileDataPtr += 4;
|
||||||
|
|
||||||
if (signature != 0x20584F56) //56 4F 58 20
|
if ((signature[0] != 'V') && (signature[0] != 'O') && (signature[0] != 'X') && (signature[0] != ' '))
|
||||||
{
|
{
|
||||||
return VOX_ERROR_INVALID_FORMAT; //"Not an MagicaVoxel File format"
|
return VOX_ERROR_INVALID_FORMAT; //"Not an MagicaVoxel File format"
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long version;
|
// @raysan5: reviewed version loading
|
||||||
|
unsigned int version = 0;
|
||||||
version = *((unsigned long*)fileDataPtr);
|
version = ((unsigned int*)fileDataPtr)[0];
|
||||||
fileDataPtr += sizeof(unsigned long);
|
fileDataPtr += 4;
|
||||||
|
|
||||||
if (version < 150)
|
if (version < 150)
|
||||||
{
|
{
|
||||||
|
@ -572,9 +577,9 @@ int Vox_LoadFromMemory(unsigned char* pvoxData, unsigned int voxDataSize, VoxArr
|
||||||
//// children chunks : m bytes
|
//// children chunks : m bytes
|
||||||
//{ child chunk 0 }
|
//{ child chunk 0 }
|
||||||
//{ child chunk 1 }
|
//{ child chunk 1 }
|
||||||
unsigned long sizeX, sizeY, sizeZ;
|
unsigned int sizeX, sizeY, sizeZ;
|
||||||
sizeX = sizeY = sizeZ = 0;
|
sizeX = sizeY = sizeZ = 0;
|
||||||
unsigned long numVoxels = 0;
|
unsigned int numVoxels = 0;
|
||||||
|
|
||||||
while (fileDataPtr < endfileDataPtr)
|
while (fileDataPtr < endfileDataPtr)
|
||||||
{
|
{
|
||||||
|
@ -583,23 +588,23 @@ int Vox_LoadFromMemory(unsigned char* pvoxData, unsigned int voxDataSize, VoxArr
|
||||||
szChunkName[4] = 0;
|
szChunkName[4] = 0;
|
||||||
fileDataPtr += 4;
|
fileDataPtr += 4;
|
||||||
|
|
||||||
unsigned long chunkSize = *((unsigned long*)fileDataPtr);
|
unsigned int chunkSize = *((unsigned int*)fileDataPtr);
|
||||||
fileDataPtr += sizeof(unsigned long);
|
fileDataPtr += sizeof(unsigned int);
|
||||||
|
|
||||||
//unsigned long chunkTotalChildSize = *((unsigned long*)fileDataPtr);
|
//unsigned long chunkTotalChildSize = *((unsigned long*)fileDataPtr);
|
||||||
fileDataPtr += sizeof(unsigned long);
|
fileDataPtr += sizeof(unsigned int);
|
||||||
|
|
||||||
if (strcmp(szChunkName, "SIZE") == 0)
|
if (strcmp(szChunkName, "SIZE") == 0)
|
||||||
{
|
{
|
||||||
//(4 bytes x 3 : x, y, z )
|
//(4 bytes x 3 : x, y, z )
|
||||||
sizeX = *((unsigned long*)fileDataPtr);
|
sizeX = *((unsigned int*)fileDataPtr);
|
||||||
fileDataPtr += sizeof(unsigned long);
|
fileDataPtr += sizeof(unsigned int);
|
||||||
|
|
||||||
sizeY = *((unsigned long*)fileDataPtr);
|
sizeY = *((unsigned int*)fileDataPtr);
|
||||||
fileDataPtr += sizeof(unsigned long);
|
fileDataPtr += sizeof(unsigned int);
|
||||||
|
|
||||||
sizeZ = *((unsigned long*)fileDataPtr);
|
sizeZ = *((unsigned int*)fileDataPtr);
|
||||||
fileDataPtr += sizeof(unsigned long);
|
fileDataPtr += sizeof(unsigned int);
|
||||||
|
|
||||||
//Alloc vox array
|
//Alloc vox array
|
||||||
Vox_AllocArray(pvoxarray, sizeX, sizeZ, sizeY); //Reverse Y<>Z for left to right handed system
|
Vox_AllocArray(pvoxarray, sizeX, sizeZ, sizeY); //Reverse Y<>Z for left to right handed system
|
||||||
|
@ -610,8 +615,8 @@ int Vox_LoadFromMemory(unsigned char* pvoxData, unsigned int voxDataSize, VoxArr
|
||||||
|
|
||||||
//(numVoxels : 4 bytes )
|
//(numVoxels : 4 bytes )
|
||||||
//(each voxel: 1 byte x 4 : x, y, z, colorIndex ) x numVoxels
|
//(each voxel: 1 byte x 4 : x, y, z, colorIndex ) x numVoxels
|
||||||
numVoxels = *((unsigned long*)fileDataPtr);
|
numVoxels = *((unsigned int*)fileDataPtr);
|
||||||
fileDataPtr += sizeof(unsigned long);
|
fileDataPtr += sizeof(unsigned int);
|
||||||
|
|
||||||
while (numVoxels > 0)
|
while (numVoxels > 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue